Module:Param Parse: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 6:
local parse = {}
 
-- Generic functions --
-----------------------
 
-- Standardized "has content" function
Line 13 ⟶ 15:
end
 
-- Standardized numbers
function parse.number(num)
num = string.gsub(num or '',',','')
return tonumber(num)
end
 
-- Yes/No
local yes_no = {
['NoYes'] = falsetrue,
['N/ANo'] = 'NIL'false,
['N/A'] = 'NIL',
}
function parse.yes_no(text)
if yes_no[text] then
return text
end
return nil
end
function parse.yes_no_smw(text)
if text == 'N/A' then
return nil
end
return yes_no[text] or nil
end
 
-- Premade Params --
--------------------
 
-- Standardized name function
parse.name = {
name = 'name',
func = parse.has_content,
smw_property = 'Name',
}
 
-- Standardized image function
Line 30 ⟶ 66:
smw_func = parse.image_smw,
empty = '[[Special:Upload|Please upload an image!]]',
category_incomplete = 'Needs image',
}
 
 
-- Standardized numbers
function parse.number(num)
num = string.gsub(num or '',',','')
return tonumber(num)
end
 
 
-- Episode
local valid_episodes = {['Hopeport'] = 1, ['Hopeforest'] = 1, ['Mine of Mantuban'] = 1, ['Crenopolis'] = 1}
function parse.episodeepisode_func(episode)
if valid_episodes[episode] then
return '[[File:'..episode..' episode icon.png|18px]] [['..episode..']]'
Line 55 ⟶ 84:
return nil
end
parse.episode = {
name = 'episode',
func = parse.episode_func,
smw_property = 'Episode',
smw_func = parse.episode_smw,
category_incomplete = 'Needs episode',
}
 
-- Premium
 
parse.premium = {
-- Yes/No
name = 'premium',
local yes_no = {
['Yes']func = trueparse.yes_no,
smw_property = 'Premium',
['No'] = false,
smw_func = parse.yes_no,
['N/A'] = 'NIL',
category_incomplete = 'Needs premium status',
}
 
function parse.yes_no(text)
if yes_no[text] then
return text
end
return nil
end
function parse.yes_no_smw(text)
if text == 'N/A' then
return nil
end
return yes_no[text] or nil
end