Module:MOS intro: Difference between revisions

Ganaram inukshuk (talk | contribs)
Corrected step count output for multi-period mosses
Ganaram inukshuk (talk | contribs)
m Removed redundant require-utils, made some code more readable
Line 3: Line 3:
local utils = require('Module:Utils')
local utils = require('Module:Utils')
local et = require('Module:ET')
local et = require('Module:ET')
local utils = require('Module:Utils')
local p = {}
local p = {}


Line 15: Line 14:
end
end


-- Function that creates a mos intro sentence, given a mos
-- Function that creates a mos intro sentence, given a mos and any other names
function p.mos_intro_sentence(input_mos, other_names)
function p.mos_intro_sentence(input_mos, other_names)
local input_mos = input_mos or mos.new(4, 5, 3)
local input_mos = input_mos or mos.new(4, 5, 3)
Line 41: Line 40:
local tamnams_name = mos.tamnams_name[scale_sig] or ""
local tamnams_name = mos.tamnams_name[scale_sig] or ""
local mos_names = p.parse_entries(tamnams_name)
local mos_names = p.parse_entries(tamnams_name)
-- Tokenize the other names passed in, then add them to the mos names
local other_names_tokenized = p.parse_entries(other_names)
local other_names_tokenized = p.parse_entries(other_names)
-- Combine the two arrays
for i = 1, #other_names_tokenized do
for i = 1, #other_names_tokenized do
mos_names[#mos_names + 1] = other_names_tokenized[i]
mos_names[#mos_names + 1] = other_names_tokenized[i]
Line 69: Line 68:
-- Add the mos names, if any
-- Add the mos names, if any
if #mos_names == 1 then
if #mos_names == 1 then
-- Only one mos name
intro = intro .. ", also called '''" .. mos_names[1] .. "''', is a"
intro = intro .. ", also called '''" .. mos_names[1] .. "''', is a"
elseif #mos_names == 2 then
elseif #mos_names == 2 then
-- Two mos names (name and alternate-name)
intro = intro .. ", also called '''" .. mos_names[1] .. "''' or '''" .. mos_names[2] .. "''', is a"
intro = intro .. ", also called '''" .. mos_names[1] .. "''' or '''" .. mos_names[2] .. "''', is a"
elseif #mos_names > 2 then
elseif #mos_names > 2 then
-- Three or more mos names (name, alternate-name, and other-alternate-name)
intro = intro .. ", also called "
intro = intro .. ", also called "
for i = 1, #mos_names - 1 do
for i = 1, #mos_names - 1 do
Line 79: Line 81:
intro = intro .. "or '''" .. mos_names[#mos_names] .. "''', is a"
intro = intro .. "or '''" .. mos_names[#mos_names] .. "''', is a"
else
else
-- No names
intro = intro .. " is a"
intro = intro .. " is a"
end
end
Line 139: Line 142:
-- Add the generator range
-- Add the generator range
local collapsed_gen_in_cents = utils._round_dec(et.cents(equalized_et, gen_equalized_in_steps), round)
local collapsed_gen_in_cents = et.cents(equalized_et, gen_equalized_in_steps)
local equalized_gen_in_cents = utils._round_dec(et.cents(collapsed_et, gen_collapsed_in_steps), round)
local equalized_gen_in_cents = et.cents(collapsed_et, gen_collapsed_in_steps)
intro = intro .. "This scale is made using a [[generator]] ranging from " .. collapsed_gen_in_cents
intro = intro .. "This scale is made using a [[generator]] ranging from " .. utils._round_dec(collapsed_gen_in_cents, round)
intro = intro .. "¢ to " .. equalized_gen_in_cents .. "¢."
intro = intro .. "¢ to " .. utils._round_dec(equalized_gen_in_cents, round) .. "¢."
return intro
return intro