Jump to content

Module:Series overview

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 03:44, 6 July 2016 (make a start at a replacement for Template:Series overview). 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 {{series overview}}.

require('Module:No globals')
local lang = mw.language.getContentLanguage()

--------------------------------------------------------------------------------
-- EpisodeGroup class
-- A consecutive run of episodes. There is usually only one of these in a
-- season, but there can be more if the season is split.
--------------------------------------------------------------------------------

local EpisodeGroup = {}

function EpisodeGroup.new(options)
	options = options or {}
	local obj = {}

	-- Validates a date and returns it in YYYY-MM-DD format.
	local function validateDate(date)
		if not date then
			return nil
		end
		local success, ret = pcall(function ()
			return lang:formatDate('Y-m-d', date)
		end)
		if success then
			return ret
		else
			error(string.format('"%s" is not a valid date', tostring(date)), 3)
		end
	end

	local startDate = validateDate(options.startDate)
	local endDate = validateDate(options.endDate)
	local info = {}
	if options.info then
		for i, v in ipairs(options.info) do
			info[i] = v
		end
	end

	function obj:getColor()
		return options.color
	end
	
	function obj:getStartDate()
		return startDate
	end
	
	function obj:getEndDate()
		return endDate
	end
	
	function obj:getNetwork()
		return options.network
	end

	return obj
end

--------------------------------------------------------------------------------
-- SeriesEntry class
-- This can represent a season or a special.
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- Series class
-- The main class.
--------------------------------------------------------------------------------