Module:ED intro: Difference between revisions
ArrowHead294 (talk | contribs) mNo edit summary |
Address Template talk: ED intro #Square/cube root of 2. Now square/cube root are displayed instead of 2nd/3rd root |
||
| (8 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local ord = require("Module:Ordinal") | local ord = require("Module:Ordinal") | ||
local rat = require("Module:Rational") | |||
local utils = require("Module:Utils") | local utils = require("Module:Utils") | ||
local yesno = require("Module:Yesno") | local yesno = require("Module:Yesno") | ||
local p = {} | local p = {} | ||
| Line 38: | Line 38: | ||
local edstep_size_rounded = utils._round(edstep_size, 3) | local edstep_size_rounded = utils._round(edstep_size, 3) | ||
local is_exact = edstep_size - edstep_size_rounded == 0 | local is_exact = edstep_size - edstep_size_rounded == 0 | ||
local intro_text = "" | local intro_text = "" | ||
| Line 52: | Line 50: | ||
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | ||
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | ||
intro_text = string.gsub(intro_text, "''kth''", | intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed)) | ||
return intro_text | return intro_text | ||
| Line 66: | Line 64: | ||
local edstep_size_rounded = utils._round(edstep_size, 3) | local edstep_size_rounded = utils._round(edstep_size, 3) | ||
local is_exact = edstep_size - edstep_size_rounded == 0 | local is_exact = edstep_size - edstep_size_rounded == 0 | ||
local intro_text = "" | local intro_text = "" | ||
| Line 80: | Line 76: | ||
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | ||
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | ||
intro_text = string.gsub(intro_text, "''kth''", | intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed)) | ||
return intro_text | return intro_text | ||
| Line 94: | Line 90: | ||
local edstep_size_rounded = utils._round(edstep_size, 3) | local edstep_size_rounded = utils._round(edstep_size, 3) | ||
local is_exact = edstep_size - edstep_size_rounded == 0 | local is_exact = edstep_size - edstep_size_rounded == 0 | ||
local intro_text = "" | local intro_text = "" | ||
| Line 108: | Line 102: | ||
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | ||
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | ||
intro_text = string.gsub(intro_text, "''kth''", | intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed)) | ||
return intro_text | return intro_text | ||
| Line 123: | Line 117: | ||
local edstep_size_rounded = utils._round(edstep_size, 3) | local edstep_size_rounded = utils._round(edstep_size, 3) | ||
local is_exact = edstep_size - edstep_size_rounded == 0 | local is_exact = edstep_size - edstep_size_rounded == 0 | ||
local intro_text = "" | local intro_text = "" | ||
| Line 137: | Line 129: | ||
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | ||
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | ||
intro_text = string.gsub(intro_text, "''kth''", | intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed)) | ||
intro_text = string.gsub(intro_text, "hth", ord._ordinal(harmonic)) | intro_text = string.gsub(intro_text, "hth", ord._ordinal(harmonic)) | ||
intro_text = string.gsub(intro_text, "''h''", harmonic) | intro_text = string.gsub(intro_text, "''h''", harmonic) | ||
| Line 154: | Line 146: | ||
local edstep_size_rounded = utils._round(edstep_size, 3) | local edstep_size_rounded = utils._round(edstep_size, 3) | ||
local is_exact = edstep_size - edstep_size_rounded == 0 | local is_exact = edstep_size - edstep_size_rounded == 0 | ||
local intro_text = "" | local intro_text = "" | ||
| Line 168: | Line 158: | ||
intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | intro_text = string.gsub(intro_text, "exactly/about", (is_exact and "exactly" or "about")) | ||
intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | intro_text = string.gsub(intro_text, "''s''", utils._round (edstep_size, 3)) | ||
intro_text = string.gsub(intro_text, "''kth''", | intro_text = string.gsub(intro_text, "''kth''", p.root_ordinal(ed)) | ||
intro_text = string.gsub(intro_text, "''p/q''", rat.as_ratio(ratio)) | intro_text = string.gsub(intro_text, "''p/q''", rat.as_ratio(ratio)) | ||
| Line 183: | Line 173: | ||
local edstep_size_rounded = utils._round(edstep_size, 3) | local edstep_size_rounded = utils._round(edstep_size, 3) | ||
local is_exact = edstep_size - edstep_size_rounded == 0 | local is_exact = edstep_size - edstep_size_rounded == 0 | ||
local intro_text = "" | local intro_text = "" | ||
| Line 200: | Line 188: | ||
return intro_text | return intro_text | ||
end | |||
-- ord._ordinal but for roots | |||
function p.root_ordinal(n) | |||
local result = ord._ordinal(n) | |||
if n == 2 then | |||
result = "square" | |||
elseif n == 3 then | |||
result = "cube" | |||
end | |||
return result | |||
end | end | ||
| Line 299: | Line 298: | ||
if ed_type == ED_TYPE_DEFAULT then | if ed_type == ED_TYPE_DEFAULT then | ||
return "{{error|Equave type not supported or entered incorrectly.}}" | return "{{error|Error: Equave type not supported or entered incorrectly.}}" | ||
elseif ed_type == ED_TYPE_EDO then | elseif ed_type == ED_TYPE_EDO then | ||
return p.edo_intro(parsed_ed) | return p.edo_intro(parsed_ed) | ||
| Line 337: | Line 336: | ||
local edo = frame.args["EDO"] -- For backwards compatibility with edo intro | local edo = frame.args["EDO"] -- For backwards compatibility with edo intro | ||
local debugg = yesno(frame.args["debug"]) | local debugg = yesno(frame.args["debug"]) | ||
local result = p._ed_intro((edo == nil) and ed or edo) | |||
if debugg == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return frame:preprocess(result) | |||
end | end | ||
return p | return p | ||