Module:Infobox interval: Difference between revisions

Plumtree (talk | contribs)
m More categories
Plumtree (talk | contribs)
m Refactoring
Line 5: Line 5:
local i = require('Module:Interval')
local i = require('Module:Interval')
local infobox = require('Module:Infobox')
local infobox = require('Module:Infobox')
-- check whether the input is a non-empty string
local function value_provided(s)
return type(s) == 'string' and #s > 0
end


function p.infobox_interval(frame)
function p.infobox_interval(frame)
Line 22: Line 27:
-- intervals with relatively small powers
-- intervals with relatively small powers
if frame.args['Ratio'] and #(frame.args['Ratio']) > 0 then
if value_provided(frame.args['Ratio']) then
ratio = rat.parse(frame.args['Ratio'])
ratio = rat.parse(frame.args['Ratio'])
if ratio ~= nil then
if ratio ~= nil then
Line 35: Line 40:
-- intervals with large powers
-- intervals with large powers
if ratio == nil and frame.args['Ket'] and #(frame.args['Ket']) > 0 then
if ratio == nil and value_provided(frame.args['Ket']) then
ratio = rat.from_ket(frame.args['Ket'])
ratio = rat.from_ket(frame.args['Ket'])
if ratio ~= nil then
if ratio ~= nil then
Line 44: Line 49:
ket = rat.as_ket(ratio, frame)
ket = rat.as_ket(ratio, frame)
end
end
elseif ratio ~= nil and frame.args['Ket'] and #(frame.args['Ket']) > 0 then
elseif ratio ~= nil and value_provided(frame.args['Ket']) then
cats = cats .. '[[Category:Todo:remove explicit Ket]]'
cats = cats .. '[[Category:Todo:remove explicit Ket]]'
end
end
-- irrational intervals
-- irrational intervals
if ratio == nil and frame.args['Cents'] and #(frame.args['Cents']) > 0 then
if ratio == nil and value_provided(frame.args['Cents']) then
cents = tonumber(frame.args['Cents'])
cents = tonumber(frame.args['Cents'])
if cents ~= nil then
if cents ~= nil then
Line 57: Line 62:
ratio_string = frame.args['Ratio'] or ''
ratio_string = frame.args['Ratio'] or ''
end
end
elseif ratio ~= nil and frame.args['Cents'] and #(frame.args['Cents']) > 0 then
elseif ratio ~= nil and value_provided(frame.args['Cents']) then
cats = cats .. '[[Category:Todo:remove explicit Cents]]'
cats = cats .. '[[Category:Todo:remove explicit Cents]]'
end
end
Line 146: Line 151:
end
end
local is_comma = frame.args['Comma'] and #(frame.args['Comma']) > 0
local is_comma = value_provided(frame.args['Comma'])
local comma = nil
local comma = nil
if is_comma and regular and cents > 0 then
if is_comma and regular and cents > 0 then
Line 186: Line 191:


local name = frame.args['Name']
local name = frame.args['Name']
if name and #name > 0 then
if value_provided(name) then
local caption = 'Name'
local caption = 'Name'
if name:match(',') then
if name:match(',') then
Line 210: Line 215:
local colour_name = frame.args['Color name']
local colour_name = frame.args['Color name']
if colour_name and #colour_name > 0 then
if value_provided(colour_name) then
table.insert(infobox_data, {
table.insert(infobox_data, {
'[[Color notation|Color name]]',
'[[Color notation|Color name]]',
Line 220: Line 225:
local FJS_name = frame.args['FJS name']
local FJS_name = frame.args['FJS name']
if (not FJS_name or #FJS_name == 0) and rational and regular then
if not value_provided(FJS_name) and rational and regular then
FJS_name = rat.as_FJS(ratio)
FJS_name = rat.as_FJS(ratio)
elseif FJS_name and #FJS_name > 0 then
elseif value_provided(FJS_name) then
FJS_name = FJS_name:gsub('%s', '')
FJS_name = FJS_name:gsub('%s', '')
FJS_name = FJS_name:gsub('<br/?>', '')
FJS_name = FJS_name:gsub('<br/?>', '')
Line 229: Line 234:
cats = cats .. '[[Category:Todo:remove explicit FJS name]]'
cats = cats .. '[[Category:Todo:remove explicit FJS name]]'
end
end
if FJS_name and #FJS_name > 0 then
if value_provided(FJS_name) then
FJS_name = FJS_name:gsub('^(%w+)', '\\text{%1}')
FJS_name = FJS_name:gsub('^(%w+)', '\\text{%1}')
table.insert(infobox_data, {
table.insert(infobox_data, {
Line 267: Line 272:
local sound = frame.args['Sound']
local sound = frame.args['Sound']
if sound and #sound > 0 then
if value_provided(sound) then
cats = cats .. '[[Category:Pages with internal sound examples]]'
cats = cats .. '[[Category:Pages with internal sound examples]]'
table.insert(infobox_data, {
table.insert(infobox_data, {