Jump to content

Module:Indian Premier League teams: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Jfd34 (talk | contribs)
No edit summary
Jfd34 (talk | contribs)
Remove functions so that the module can be used with mw.loadData()
Line 146: Line 146:
_teams.bang = _teams.RCB
_teams.bang = _teams.RCB
_teams.raja = _teams.RR
_teams.raja = _teams.RR

------------- Module functions -------------

--[[
getTeamCode(team)
Returns the code of the team. If the team does not exist, returns the empty string.
team: The code, full name, short name or {{cr-IPL}} code of the team for which to return the code.
]]
function _teams.getTeamCode(frame)
local t = _teams[frame.args[1] or ""]
if t then
return t.code or ""
end
return ""
end

--[[
getTeamCode(team)
Returns the full name of the team. If the team does not exist, returns the empty string.
team: The code, full name, short name or {{cr-IPL}} code of the team for which to return the full name.
]]
function _teams.getFullName(frame)
local t = _teams[frame.args[1] or ""]
if t then
return t.fullName or ""
end
return ""
end

--[[
getTeamCode(team)
Returns the short name of the team. If the team does not exist, returns the empty string.
team: The code, full name, short name or {{cr-IPL}} code of the team for which to return the short name.
]]
function _teams.getShortName(frame)
local t = _teams[frame.args[1] or ""]
if t then
return t.shortName or ""
end
return ""
end

--[[
teamExists(team, year = nil)
If the team exists, returns "1", otherwise returns the empty string.
This can be used in wikitext such as {{#if: {{#invoke: IndianPremierLeague/Teams|teamExists|<teamName>}}| ... | ...}}
team: The code, full name, short name or {{cr-IPL}} code of the team to check.
year: Optional. If specified, checks whether the team existed in the given year.
]]
function _teams.teamExists(frame)
local t, year = _teams[frame.args[1] or ""], tonumber(frame.args[2])
local endYear = t.endYear
if t and (not year or (t.startYear <= year and (not endYear or endYear >= year))) then
return "1"
end
return ""
end


return _teams
return _teams

Revision as of 16:38, 6 April 2014

--[[
    Each team must have a table with the following keys:
    code: A short code of 2-4 letters (uppercase) to represent the team.
    fullName: The full name of the team.
    shortName: The short name of the team, usually the location in which it is based.
    pageName: The title of the team's article on Wikipedia. This is usually the team's full name, but if disambiguation is
              needed, it may be different.
    startYear: The year in which the team first played.
    endYear: The year in which the team last played. (For inactive/disbanded/terminated teams only)
]]

local _teams = {
    
    CSK = {
        code       = "CSK",
        fullName   = "Chennai Super Kings",
        shortName  = "Chennai",
        pageName   = "Chennai Super Kings",
        startYear  = 2008,
    },
    
    DC = {
        code       = "DC",
        fullName   = "Deccan Chargers",
        shortName  = "Deccan",
        pageName   = "Deccan Chargers",
        startYear  = 2008,
        endYear    = 2012,
    },
    
    DD = {
        code       = "DD",
        fullName   = "Delhi Daredevils",
        shortName  = "Delhi",
        pageName   = "Delhi Daredevils",
        startYear  = 2008,
    },
    
    KKR = {
        code       = "KKR",
        fullName   = "Kolkata Knight Riders",
        shortName  = "Kolkata",
        pageName   = "Kolkata Knight Riders",
        startYear  = 2008,
    },
    
    KTK = {
        code       = "KTK",
        fullName   = "Kochi Tuskers Kerala",
        shortName  = "Kochi",
        pageName   = "Kochi Tuskers Kerala",
        startYear  = 2011,
        endYear    = 2011,
    },
    
    KXIP = {
        code       = "KXIP",
        fullName   = "Kings XI Punjab",
        shortName  = "Punjab",
        pageName   = "Kings XI Punjab",
        startYear  = 2008,
    },
    
    MI = {
        code       = "MI",
        fullName   = "Mumbai Indians",
        shortName  = "Mumbai",
        pageName   = "Mumbai Indians",
        startYear  = 2008,
    },
    
    PWI = {
        code       = "PWI",
        fullName   = "Pune Warriors India",
        shortName  = "Pune",
        pageName   = "Pune Warriors India",
        startYear  = 2011,
        endYear    = 2013,
    },
    
    SRH = {
        code       = "SRH",
        fullName   = "Sunrisers Hyderabad",
        shortName  = "Hyderabad",
        pageName   = "Sunrisers Hyderabad",
        startYear  = 2013,
    },
    
    RCB = {
        code       = "RCB",
        fullName   = "Royal Challengers Bangalore",
        shortName  = "Bangalore",
        pageName   = "Royal Challengers Bangalore",
        startYear  = 2008,
    },
    
    RR = {
        code       = "RR",
        fullName   = "Rajasthan Royals",
        shortName  = "Rajasthan",
        pageName   = "Rajasthan Royals",
        startYear  = 2008,
    },
    
}

------------- Full names -------------

_teams["Chennai Super Kings"] = _teams.CSK
_teams["Deccan Chargers"] = _teams.DC
_teams["Delhi Daredevils"] = _teams.DD
_teams["Kolkata Knight Riders"] = _teams.KKR
_teams["Kochi Tuskers Kerala"] = _teams.KTK
_teams["Kings XI Punjab"] = _teams.KXIP
_teams["Mumbai Indians"] = _teams.MI
_teams["Pune Warriors India"] = _teams.PWI
_teams["Sunrisers Hyderabad"] = _teams.SRH
_teams["Royal Challengers Bangalore"] = _teams.RCB
_teams["Rajasthan Royals"] = _teams.RR

------------- Short names -------------

_teams["Chennai"] = _teams.CSK
_teams["Deccan"] = _teams.DC
_teams["Delhi"] = _teams.DD
_teams["Kolkata"] = _teams.KKR
_teams["Kochi"] = _teams.KTK
_teams["Punjab"] = _teams.KXIP
_teams["Mumbai"] = _teams.MI
_teams["Pune"] = _teams.PWI
_teams["Hyderabad"] = _teams.SRH
_teams["Bangalore"] = _teams.RCB
_teams["Rajasthan"] = _teams.RR

------------- Codes used by {{cr-IPL}} -------------

_teams.chen = _teams.CSK
_teams.decc = _teams.DC
_teams.delhi = _teams.DD
_teams.kolk = _teams.KKR
_teams.koch = _teams.KTK
_teams.kings = _teams.KXIP
_teams.mumb = _teams.MI
_teams.pune = _teams.PWI
_teams.hyde = _teams.SRH
_teams.bang = _teams.RCB
_teams.raja = _teams.RR

return _teams