Module:MOS: Difference between revisions

Ganaram inukshuk (talk | contribs)
comment review
Ganaram inukshuk (talk | contribs)
mNo edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- This module follows User:Ganaram inukshuk/Provisional style guide for Lua#Lua_style
-- This module follows [[User:Ganaram inukshuk/Provisional style guide for Lua]]
local et    = require("Module:ET")
local rat  = require("Module:Rational")
local utils = require("Module:Utils")


local rat = require("Module:Rational")
local utils = require("Module:Utils")
local et = require("Module:ET")
local p = {}
local p = {}
--------------------------------------------------------------------------------
------------------------------- HELPER FUNCTIONS -------------------------------
--------------------------------------------------------------------------------
-- Helper function
function p.find_item_in_table(table, item)
local item_found = false
for i = 1, #table do
if table[i] == item then
item_found = true
break
end
end
return item_found
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 40: Line 23:
-- If no equave "p/q" is provided, it's assumed to be 2/1-equivalent.
-- If no equave "p/q" is provided, it's assumed to be 2/1-equivalent.
function p.parse(unparsed)
function p.parse(unparsed)
local nL, ns, equave = unparsed:match("^(%d+)[Ll]%s*(%d+)[Ss]%s*(.*)$")
local nL, ns, equave = unparsed:match("^(%d+)[Ll].-(%d+)[Ss]%s*(.*)$")
nL = tonumber(nL)
nL = tonumber(nL)
ns = tonumber(ns)
ns = tonumber(ns)
Line 88: Line 71:
suffix = "⟨" .. rat.as_ratio(mos.equave):lower() .. "⟩"
suffix = "⟨" .. rat.as_ratio(mos.equave):lower() .. "⟩"
end
end
return "" .. mos.nL .. "L" .. (use_nbsp and " " or " ") .. mos.ns .. "s" .. suffix
return mos.nL .. "L" .. (use_nbsp and " " or " ") .. mos.ns .. "s" .. suffix
else
else
return "" .. math.max(mos.nL, mos.ns) .. p.et_suffix(mos)
return math.max(mos.nL, mos.ns) .. p.et_suffix(mos)
end
end
end
end
Line 106: Line 89:
suffix = (use_nbsp and " " or " ") .. string.format("(%s-equivalent)", rat.as_ratio(mos.equave):lower())
suffix = (use_nbsp and " " or " ") .. string.format("(%s-equivalent)", rat.as_ratio(mos.equave):lower())
end
end
return "" .. mos.nL .. "L" .. (use_nbsp and " " or " ") .. mos.ns .. "s" .. suffix
return mos.nL .. "L" .. (use_nbsp and " " or " ") .. mos.ns .. "s" .. suffix
else
else
return "" .. math.max(mos.nL, mos.ns) .. p.et_suffix(mos)
return math.max(mos.nL, mos.ns) .. p.et_suffix(mos)
end
end
end
end
Line 121: Line 104:
return string.format("[[%s]]", link)
return string.format("[[%s]]", link)
else
else
return string.format("[[%s | %s]]", link, text)
return string.format("[[%s|%s]]", link, text)
end
end
end
end
Line 307: Line 290:
local current_mode = mode_string
local current_mode = mode_string
for i = 1, #mode_string do
for i = 1, #mode_string do
if not p.find_item_in_table(rotations, current_mode) then
if not utils.table_contains(rotations, current_mode) then
table.insert(rotations, current_mode)
table.insert(rotations, current_mode)
end
end
Line 560: Line 543:
------------------------------- COUNT FUNCTIONS --------------------------------
------------------------------- COUNT FUNCTIONS --------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Given a mos, return the number of steps.
function p.step_count(mos)
return mos.nL + mos.ns
end


-- Given a mos, compute the number of steps in its bright gen (L's plus s's).
-- Given a mos, compute the number of steps in its bright gen (L's plus s's).
Line 577: Line 565:
end
end


-- Given a mos, compute the number of steps in its equave (L's plus s's).
-- TODO: deprecate this since "equave_step_count" is redundant and longer than
-- "step count".
function p.equave_step_count(mos)
function p.equave_step_count(mos)
return mos.nL + mos.ns
return mos.nL + mos.ns