Module:Param Parse: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 6: Line 6:
local parse = {}
local parse = {}


-- Generic functions --
-----------------------


-- Standardized "has content" function
-- Standardized "has content" function
Line 13: Line 15:
end
end


-- Standardized numbers
function parse.number(num)
num = string.gsub(num or '',',','')
return tonumber(num)
end

-- Yes/No
local yes_no = {
['Yes'] = true,
['No'] = 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
-- Standardized image function
Line 30: Line 66:
smw_func = parse.image_smw,
smw_func = parse.image_smw,
empty = '[[Special:Upload|Please upload an image!]]',
empty = '[[Special:Upload|Please upload an image!]]',
category_incomplete = 'Needs image'
category_incomplete = 'Needs image',
}
}


-- Standardized numbers
function parse.number(num)
num = string.gsub(num or '',',','')
return tonumber(num)
end




-- Episode
-- Episode
local valid_episodes = {['Hopeport'] = 1, ['Hopeforest'] = 1, ['Mine of Mantuban'] = 1, ['Crenopolis'] = 1}
local valid_episodes = {['Hopeport'] = 1, ['Hopeforest'] = 1, ['Mine of Mantuban'] = 1, ['Crenopolis'] = 1}
function parse.episode(episode)
function parse.episode_func(episode)
if valid_episodes[episode] then
if valid_episodes[episode] then
return '[[File:'..episode..' episode icon.png|18px]] [['..episode..']]'
return '[[File:'..episode..' episode icon.png|18px]] [['..episode..']]'
Line 55: Line 84:
return nil
return nil
end
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'] = true,
func = parse.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