Module:MaroScale: Difference between revisions

From MTG Wiki
Jump to navigation Jump to search
>Corveroth
No edit summary
>Corveroth
No edit summary
Line 26: Line 26:
local row = mw.html.create("tr")
local row = mw.html.create("tr")
:tag("td"):wikitext(name or "Name not given"):done()
row:tag("td"):wikitext(name or "Name not given")
:tag("td"):wikitext(highest or "Rating not found"):done()
row:tag("td"):wikitext(highest or "Rating not found")
:tag("td"):tag("ul")
local list = row:tag("td"):tag("ul")
for _, rating in pairs(ratings) do
for _, rating in pairs(ratings) do
row:tag("li"):wikitext(rating.refString):done()
list:tag("li"):wikitext(rating.refString)
end
end

Revision as of 02:56, 3 December 2016

Documentation for this module may be created at Module:MaroScale/doc

-- Little bit of Lua for building tables for the Storm and Rabiah scales.
-- Mechanics have be re-ranked in the past, and it's probably interesting to track their drift.
-- Rather than force editors to track the newest one, let's see if we can't do it in code.

local MaroScale = {}

function MaroScale.RowBuilder(frame)
	local args = frame:getParent().args -- coming from one layer up
	
	local name = args.name
	
	local highest = 0
	-- local highestDate = ""
	local ratings = {}
	string.gsub(args.ratings, "({.-})", function(a)
		local rating, refDate, refString = string.match(a, "(%d+),([%d%-]+),(.+)")
		rating = tonumber(rating)
		table.insert(ratings, {rating = rating, refDate = refDate, refString = refString})
		if rating > highest then
			highest = rating
			-- highestDate = refDate
		end
	end)
	-- maybe later, it's not worth the effort right now
	-- table.sort(ratings, function(a,b) return a.refDate < b.refDate end)
	
	local row = mw.html.create("tr")
	row:tag("td"):wikitext(name or "Name not given")
	row:tag("td"):wikitext(highest or "Rating not found")
	local list = row:tag("td"):tag("ul")
	for _, rating in pairs(ratings) do
		list:tag("li"):wikitext(rating.refString)
	end
	
	return row
end

return MaroScale