Module:MOS notation: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Fixed param names in parse functions (they're all called "unparsed")
Ganaram inukshuk (talk | contribs)
Module now uses ordinal module
Line 4: Line 4:
local mos = require('Module:MOS')
local mos = require('Module:MOS')
local rat = require('Module:Rational')
local rat = require('Module:Rational')
local ord = require('Module:Ordinal')
local p = {}
local p = {}


Line 185: Line 186:
return genchains
return genchains
end
-- Helper function for ordinals (added out of haste)
-- Pulled from: https://stackoverflow.com/questions/20694133/how-to-to-add-th-or-rd-to-the-date
function p.ordinal_number(n)
  local ordinal, digit = {"st", "nd", "rd"}, string.sub(n, -1)
  if tonumber(digit) > 0 and tonumber(digit) <= 3 and string.sub(n,-2) ~= 11 and string.sub(n,-2) ~= 12 and string.sub(n,-2) ~= 13 then
    return n .. ordinal[tonumber(digit)]
  else
    return n .. "th"
  end
end
end


Line 224: Line 214:
-- Add a dash between the prefix and ordinal, if a prefix is given
-- Add a dash between the prefix and ordinal, if a prefix is given
if prefix == "" then
if prefix == "" then
degree_name = p.ordinal_number(mossteps + 1)
degree_name = ord._ordinal(mossteps + 1)
else
else
degree_name = prefix .. "-" .. p.ordinal_number(mossteps + 1)
degree_name = prefix .. "-" .. ord._ordinal(mossteps + 1)
end
end
end
end