Module:Param Parse: Difference between revisions

Smw support for number ranges
(Level range support)
(Smw support for number ranges)
Line 23:
end
 
-- Standardized number range: Accepts '1' and '1-5'
function parse.number_rangenumber_or_number_range(prenum)
local numret = ""''
local count = 0
for out in string.gmatch(prenum, "[^-]+") do
if count == 1 then
numret = numret .. "➨\n"
elseif count == 3 then
return nil
end
num = num parse.. string.gsubnumber(out or '',',','')
if notnum level_valid== nil then
return nil
end
ret = ret .. num
count = count + 1
end
return numret
end
 
function parse.number_or_number_range_low(prenum)
local count = 0
local value = nil
for out in string.gmatch(prenum, "[^-]+") do
if parse.number(out) == nil then
return nil
end
count = count + 1
if count == 1 then
value = out
end
if count > 2 then
return nil
end
end
return parse.number(value)
end
 
function parse.number_or_number_range_high(prenum)
local count = 0
local value = nil
for out in string.gmatch(prenum, "[^-]+") do
if parse.number(out) == nil then
return nil
end
count = count + 1
if count == 2 then
value = out
end
if count > 2 then
return nil
end
end
return parse.number(value)
end
 
Line 253 ⟶ 293:
}
 
-- Profession (TODO)
function parse.profession_bubble_func(profession, level)
local profession_valid = parse.has_content(profession)
local profession_valid_link = profession_valid
local level_valid = parse.numbernumber_or_number_range(level)
local category_error = false
if not profession_valid and not level_valid then
Line 269 ⟶ 309:
end
if profession_valid and not level_valid then
-- checkProfession ifdefined its awithout level, rangeinvalid, insteadshow an unknown level
level_valid = parse.number_range(level)'?'
category_error = true
if not level_valid then
-- Profession defined without level, invalid, show an unknown level
level_valid = '?'
category_error = true
end
end
return '[[File:'..profession_valid..' icon.png|x30px|link='..profession_valid_link..']] '..level_valid..(category_error and '[[Category:Invalid profession bubble]]' or '')
Line 303 ⟶ 339:
parse.profession_a_level_smw = {
name = 'profession_a_level',
func = parse.numbernumber_or_number_range_low,
smw_property = 'Profession Level A',
}
parse.profession_a_level_high_smw = {
name = 'profession_a_level_high',
func = {name = parse.number_or_number_range_high, params = {Infobox.raw_param('profession_a_level')}},
smw_property = 'Profession Level A High',
}
parse.profession_bubble_b = {
Line 319 ⟶ 360:
parse.profession_b_level_smw = {
name = 'profession_b_level',
func = parse.numbernumber_or_number_range_low,
smw_property = 'Profession Level B',
}
parse.profession_b_level_high_smw = {
name = 'profession_b_level_high',
func = {name = parse.number_or_number_range_high, params = {Infobox.raw_param('profession_b_level')}},
smw_property = 'Profession Level B High',
}