Module:PriceCalculator: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
local p = {}
function p._calculate(price, priceType)
function p._calculate(price, priceType)
price = tostring(price):gsub(",", "") -- remove commas
price = tonumber(price)
price = tonumber(price)
if not price or price < 0 then
if not price or price < 0 then
Line 20: Line 19:
return math.floor(price * factor + 0.5)
return math.floor(price * factor + 0.5)
end
end
function p.calculate(frame)
local args = frame:getParent().args
local price = args.price or args[1]
local priceType = args.type or args[2]
return p._calculate(price, priceType)
end
-- This makes the module callable directly without a function name
return setmetatable(p, {
__call = function(_, frame)
return p.calculate(frame)
end
})