Jump to content

Module:NLLDivisionStanding

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 17:31, 30 March 2016 (start work on converting Template:NLLDivisionStanding). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

-- This module implements {{NLLDivisionStanding}}.

local mTableTools = require('Module:TableTools')

-------------------------------------------------------------------------------
-- Helper functions
-------------------------------------------------------------------------------

local function abbr(shortForm, longForm)
	return tostring(mw.html.new('abbr')
		:attr('title', longForm)
		:wikitext(shortForm)
	)
end

-------------------------------------------------------------------------------
-- Team class
-------------------------------------------------------------------------------

local Team = {}
Team.__index = Team

Team.stringFields = {
	'name',
	'link',
	'short',
}

Team.numberFields = {
	'pos',
	'clinch_playoff',
	'clinch_division',
	'clinch_best_record',
	'ga',
	'gf',
	'home_loss',
	'home_win',
	'road_loss',
	'road_win',
}

function Team.new(options)
	options = options or {}
	local self = setmetatable({}, Team)
	for i, field in ipairs(Team.stringFields) do
		self[field] = options[field]
	end
	for i, field in ipairs(Team.numberFields) do
		self[field] = tonumber(options[field])
	end
	return self
end

function Team:getPosition()
	return tostring(self.pos) or '--'
end

function Team:getName()
	return self.name
end

function Team:getLink()
	local name = self:getName()
	local link = self.link
	if link and name then
		return string.format('[[%s|%s]]', link, name)
	elseif link then
		return string.format('[[%s]]', link)
	else
		return name
	end
end

function Team:makeDisplayName()
	local ret = self:getLink()
	if not ret then
		return nil
	end
	local clinches = {}
	-- The numerical syntax here is a hangover from the wikitext template
	-- which used #expr hacks to calculate the number of clinches
	if self.clinch_playoff == 1 then
		table.insert(clinches, 'x')
	end
	if self.clinch_playoff == 2 then
		table.insert(clinches, 'c')
	end
	if self.clinch_division == 1 then
		table.insert(clinches, 'y')
	end
	if self.clinch_best_record == 1 then
		table.insert(clinches, 'z')
	end
	if #clinches > 0 then
		ret = string.format("%s – '''%s'''", ret, table.concat(clinches))
	end
	return ret
end

function Team:getGamesPlayed()
	return self
end

function Team:getWins()
	return self
end

function Team:getLosses()
	return self
end

function Team:getWinPercentage()
	return self
end

function Team:getGamesBack()
	return self
end

function Team:getHomeRecord()
	return self
end

function Team:getRoadRecord()
	return self
end

function Team:getGoalsScored()
	return self
end

function Team:getGoalsAllowed()
	return self
end

function Team:getDifferential()
	return self
end

function Team:getGameScoredAverage()
	return self
end

function Team:getGameAllowedAverage()
	return self
end

-------------------------------------------------------------------------------
-- DivisionStanding class
-------------------------------------------------------------------------------

local DivisionStanding = {}
DivisionStanding.__index = DivisionStanding

function DivisionStanding.new(options)
	local self = setmetatable({}, DivisionStanding)
	return self
end

-------------------------------------------------------------------------------
-- Exports
-------------------------------------------------------------------------------

local p = {}

function p._main(args)
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:NLLDivisionStanding'
	})
	return p._main(args)
end

return p