Jump to content

Module:Sandbox/Gonnym/episodewikidata

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Gonnym (talk | contribs) at 09:42, 21 September 2018 (test). 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)
local convertNumeric = require('Module:ConvertNumeric').numeral_to_english_less_100

local ones_position = {
	[1] = 'st',
	[2] = 'nd',
	[3] = 'rd',
	[4] = 'th',
	[5] = 'th',
	[6] = 'th',
	[7] = 'th',
	[8] = 'th',
	[9] = 'th',
	[10] = 'th',
	[11] = 'th',
	[12] = 'th',
	[13] = 'th',
	[14] = 'th',
	[15] = 'th',
	[16] = 'th',
	[17] = 'th',
	[18] = 'th',
	[19] = 'th',
}

local tens_position = {
	[2] = 'th',
	[3] = 'th',
	[4] = 'th',
	[5] = 'th',
	[6] = 'th',
	[7] = 'th',
	[8] = 'th',
	[9] = 'th',
}

local p = {}

function p.getFormmatedArticleLink(frame)
		local seasonNumber = frame.args[1]
		local episodeNumber = frame.args[2]
		local tvSeriesName = frame.args[3]
				
		local seasonOrdinalNumber = convertNumeric(seasonNumber, true, false, nil)
		local episodeOrdinalNumber = getEpisodeOrdinalNumber(episodeNumber)
		local shortDescription = getShortDescription(episodeOrdinalNumber, seasonOrdinalNumber, tvSeriesName)
		
		return shortDescription
end
		
local function getEpisodeOrdinalNumber(number)
	local ordinalIndicator = getOrdinalIndicatorLessThan1000(number)
	return number .. ordinalIndicator
end

-- Returns the oirdinal indicator for an integer between 0 and 1000.	
local function getOrdinalIndicatorLessThan1000(number)
	if num < 100 then
		return getOrdinalIndicatorLessThan100(number)
	elseif number % 100 == 0 then
		return tens_position[number / 100]
	else
		return getOrdinalIndicatorLessThan100(number % 100)
	end
end

-- Returns the oirdinal indicator for an integer between 0 and 100.
local function getOrdinalIndicatorLessThan100(number)
	if number == 0 then
		return zero
	elseif number < 20 then
		return ones_position[number]
	elseif number % 10 == 0 then
		return tens_position[number / 10]
	else
		return ones_positions[number % 10]
	end
end

-- 15th episode of the second season of Lost
local function getShortDescription(episodeOrdinalNumber, seasonOrdinalNumber, tvSeriesName)
	return episodeOrdinalNumber .. " episode of the " .. seasonOrdinalNumber .. " season of ''" .. tvSeriesName .. "''"
end