Module:Ordinal: Difference between revisions
creating a much needed module |
Remove sup argument (depended on yesno module which we chose not to import) |
||
| Line 9: | Line 9: | ||
local p = {} | local p = {} | ||
--[[ | --[[ | ||
| Line 17: | Line 15: | ||
Usage: | Usage: | ||
{{#invoke:Ordinal|ordinal|1=|2 | {{#invoke:Ordinal|ordinal|1=|2=}} | ||
{{#invoke:Ordinal|ordinal}} - uses the caller's parameters | {{#invoke:Ordinal|ordinal}} - uses the caller's parameters | ||
| Line 23: | Line 21: | ||
1: Any number or string. | 1: Any number or string. | ||
2: Set to "d" if the module should display "d" instead of "nd" and "rd". | 2: Set to "d" if the module should display "d" instead of "nd" and "rd". | ||
]] | ]] | ||
function p.ordinal(frame) | function p.ordinal(frame) | ||
| Line 33: | Line 30: | ||
args[1] = "{{{1}}}" | args[1] = "{{{1}}}" | ||
end | end | ||
return p._ordinal(args[1], (args[2] == 'd' | return p._ordinal(args[1], (args[2] == 'd')) | ||
end | end | ||
function p._ordinal(n, d | function p._ordinal(n, d) | ||
local x = tonumber(mw.ustring.match(n, "(%d*)%W*$")) | local x = tonumber(mw.ustring.match(n, "(%d*)%W*$")) | ||
local suffix = "th" | local suffix = "th" | ||
| Line 50: | Line 47: | ||
if d then suffix = "d" else suffix = "rd" end | if d then suffix = "d" else suffix = "rd" end | ||
end | end | ||
end | end | ||
return n .. suffix | return n .. suffix | ||