Différences entre les versions de « Module:Currency »
De Semantic MediaWiki - Sandbox
(Page créée avec « -- Пересчёт валют, задание единиц измерения для валют: -- Numerals: local data = { -- Экспортируемые имена... ») |
(anglicisation) |
||
Ligne 1 : | Ligne 1 : | ||
− | -- | + | -- Currency exchange rates, thousands, millions etc: |
-- Numerals: | -- Numerals: | ||
local data = { | local data = { | ||
− | -- | + | -- Exported function names: |
− | API = { | + | API = {'declare', 'Declare'}, |
− | -- | + | -- Errors: |
− | noNumber = " | + | noNumber = "Pass an argument", |
− | -- | + | -- Arguments: |
− | argNumber = 1, -- | + | argNumber = 1, -- number |
− | -- | + | -- 000: |
mils = { | mils = { | ||
[1] = {''}, | [1] = {''}, | ||
− | [1000] = {' | + | [1000] = {'thousand', 'tousands', 'K'}, |
− | [1000000] = {' | + | [1000000] = {'mln', 'million', 'millions', 'M'}, |
− | [1000000000] = {' | + | [1000000000] = {'bln', 'billion', 'billions', 'G'} |
}, -- mils = {...} | }, -- mils = {...} | ||
− | prop = ' | + | prop = 'Corresponds to' |
} -- local data = {...} | } -- local data = {...} | ||
Ligne 31 : | Ligne 31 : | ||
end | end | ||
− | -- | + | -- Declare a currency: |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local function implementCurrency (names, rate) | local function implementCurrency (names, rate) | ||
local declarations = {} | local declarations = {} |
Version du 2 mai 2016 à 08:43
La documentation pour ce module peut être créée à Module:Currency/doc
-- Currency exchange rates, thousands, millions etc:
-- Numerals:
local data = {
-- Exported function names:
API = {'declare', 'Declare'},
-- Errors:
noNumber = "Pass an argument",
-- Arguments:
argNumber = 1, -- number
-- 000:
mils = {
[1] = {''},
[1000] = {'thousand', 'tousands', 'K'},
[1000000] = {'mln', 'million', 'millions', 'M'},
[1000000000] = {'bln', 'billion', 'billions', 'G'}
}, -- mils = {...}
prop = 'Corresponds to'
} -- local data = {...}
local function formatNumeralError (message, ...)
if select('#', ... ) > 0 then
message = string.format(message, ...)
end
return "<span class=\"error\">" .. message .. "</span>"
end
-- Declare a currency:
local function implementCurrency (names, rate)
local declarations = {}
for ratio, numerals in pairs (data.mils) do
local units = {}
for _, numeral in ipairs (numerals) do
for __, name in ipairs (names) do
units [#units + 1] = numeral .. ' ' .. name
end
end
declarations [#declarations + 1] = '*** [[' .. data.prop .. '::' .. tostring (1 / rate / ratio) .. ' ' .. table.concat (units, ', ') .. '|' .. units [1] .. ']]'
end
return declarations
end -- local function implementCurrency (names, rate)
-- Загрузка аргументов и вызов реализации:
local function declareCurrency (args)
local ok
local rate = 1
local names = {}
-- Загрузка и проверка аргументов:
for _, arg in ipairs (args) do
if tonumber (arg) ~= nil then
-- Exchange rate:
rate = tonumber (arg)
else
-- Currency symbol or name:
names [#names + 1] = arg
end
end
return table.concat (implementCurrency (names, rate), '\n')
end -- local function declareCurrency (args)
-- Export function:
local m = {}
for _, alias in pairs (data.API) do
m [alias] = function (frame)
return declareCurrency (frame.args)
end
end
return m