Cabal Wiki
Advertisement

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

-- <pre>
-- Implements {{Alz}}
-- Original source: http://runescape.wiki/w/Module:Coins?action=history

local p = {}

local function amount(a)
	-- convert used globals to locals where possible to improve performance
	local math = math
	local string = string
	local table = table
	local mw = mw
        local expr = mw.ext.ParserFunctions.expr

	local ret = {true, true, true, true, '</span>', ' Alz'}

	--Initial tag.
	ret[1] = '<span '

	-- strip commas from input
	-- @example {{Alz|Foo}} -> '1,000'
	a = string.gsub(a, ',', '')

	-- for performance reasons, only calculate expr if required
	local a2 = tonumber(a)
	if a2 == nil then
		a = expr(a)
		a2 = tonumber(a) or 0
	end

	-- round to 2 d.p.
	a = math.floor(a2 * 100 + 0.5) / 100

	-- If we want any class add it in here.
	ret[2] = 'class=""'

	-- set a class to denote positive or negative (css sets the colour)
	if a < 0 then
		ret[3] = ' style="color: red;">'
	elseif a < 100000 then
		ret[3] = ' style="color: white;">'
	elseif a < 1000000 then
		ret[3] = ' style="color: #FFEA8A;">'
	elseif a < 10000000 then
		ret[3] = ' style="color: cyan;">'
	elseif a < 100000000 then
		ret[3] = ' style="color: limegreen;">'
	elseif a < 1000000000 then
		ret[3] = ' style="color: orange;">'
	elseif a < 10000000000 then
		ret[3] = ' style="color: cornflowerblue;">'
	elseif a < 100000000000 then
		ret[3] = ' style="color: palegreen;">'
	else
		ret[3] = ' style="color: #FE007E;">'
	end

	-- format number with commas
	ret[4] = mw.language.getContentLanguage():formatNum(a)

	return table.concat( ret )
end

--
-- {{Alz}} access point
--
function p.amount(frame)
	local args = frame:getParent().args
	-- for {{alz|111}}
	local a = args[1] or '0'
	return amount(a)
end

--
-- Module access point
--
function p._amount(a)
	a = tostring(a) or '0'
	return amount(a)
end

return p
Advertisement