Module:MLB standings: Difference between revisions

Content deleted Content added
convert wins and losses arguments to number
fix bugs
Line 3:
 
local me = { }
 
 
-- Temporary workaround for missing mw.text utilities
mw.text = mw.text or {}
 
if (mw.text.trim == nil) then
mw.text.trim = function(s)
if (s == nil) then
return ''
end
return mw.ustring.match(s, "^%s*(.-)%s*$")
end
end
-- everything up to here should be removed once mw.text becomes avaulable.
 
local function readTeamInfo(args, currentIdx)
Line 13 ⟶ 27:
end
return {
name = mw.text.trim(args[currentIdx]),
wins = tonumber(mw.text.trim(args[currentIdx+1])),
losses = tonumber(mw.text.trim(args[currentIdx+2])),
homeRecord = mw.text.trim(args[currentIdx+3]),
roadRecord = mw.text.trim(args[currentIdx+4]),
}
end -- function readTeamInfo()
Line 24 ⟶ 38:
function me.generateStandingsTable(frame)
local year = frame.args.year
local divisionyear = framemw.argstext.divisiontrim(year)
local division = mw.text.trim(frame.args.division)
 
local listOfTeams = {};
Line 67 ⟶ 82:
gamesBehind = '—'
else
gamesBehind = (leadingHalfGames
- (teamInfo.wins - teamInfo.losses)) / 2
end