Module:TAMNAMS: Difference between revisions
m Lookup functions for names/prefixes/abbrevs now can either accept mosses (defined in mos module) or their scalesigs |
Add function to preprocess step ratios; ratios can be either a 2-element array or a ratio as defined by the rational module |
||
| Line 59: | Line 59: | ||
p.tamnams_ranges_ext = { | p.tamnams_ranges_ext = { | ||
['1:1 to 2:1'] = 'soft-of-basic', | ['1:1 to 2:1'] = 'soft-of-basic', | ||
['1:1 to 6:5'] = ' | ['1:1 to 6:5'] = 'pseudocollapsed', | ||
['6:5 to 4:3'] = 'ultrasoft', | ['6:5 to 4:3'] = 'ultrasoft', | ||
['4:3 to 3:2'] = 'parasoft', | ['4:3 to 3:2'] = 'parasoft', | ||
| Line 198: | Line 198: | ||
['9L 1s'] = 'si' | ['9L 1s'] = 'si' | ||
} | } | ||
-------------------------------------------------------------------------------- | |||
------------------------------ HELPER FUNCTIONS -------------------------------- | |||
-------------------------------------------------------------------------------- | |||
-- Step ratios are entered as an array of two numeric values, or alternatively, | |||
-- as a ratio as defined by the rational module. If of the former, this helper | |||
-- function converts it to the latter. | |||
function p.preprocess_step_ratio(step_ratio) | |||
return (#step_ratio == 2 and type(step_ratio[1]) == 'number' and type(step_ratio[2]) == 'number') and rat.new(step_ratio[1], step_ratio[2]) or step_ratio | |||
end | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 227: | Line 238: | ||
-- Module:Rational is used to help simplify ratios | -- Module:Rational is used to help simplify ratios | ||
function p.lookup_step_ratio(step_ratio, use_extended) | function p.lookup_step_ratio(step_ratio, use_extended) | ||
local step_ratio = | local step_ratio = p.preprocess_step_ratio(step_ratio) | ||
local use_extended = use_extended == true | local use_extended = use_extended == true | ||
| Line 233: | Line 244: | ||
-- use_extended is used to toggle between central range and extended range | -- use_extended is used to toggle between central range and extended range | ||
local key = rat.as_ratio(step_ratio, ':') | local key = rat.as_ratio(step_ratio, ':') | ||
local named_ratio = use_extended and p.tamnams_ratios_ext[key] or p.tamnams_ratios[key] | |||
return named_ratio ~= nil and named_ratio or key | |||
end | end | ||
| Line 243: | Line 252: | ||
-- Module:Rational is used to help simplify ratios | -- Module:Rational is used to help simplify ratios | ||
function p.lookup_step_ratio_range(step_ratio_1, step_ratio_2, use_extended) | function p.lookup_step_ratio_range(step_ratio_1, step_ratio_2, use_extended) | ||
local step_ratio_1 = | local step_ratio_1 = p.preprocess_step_ratio(step_ratio_1) | ||
local step_ratio_2 = | local step_ratio_2 = p.preprocess_step_ratio(step_ratio_2) | ||
local use_extended = use_extended == true | local use_extended = use_extended == true | ||
| Line 259: | Line 268: | ||
-- use_extended is used to toggle between central range and extended range | -- use_extended is used to toggle between central range and extended range | ||
local named_ratio_range = use_extended and p.tamnams_ranges_ext[key] or p.tamnams_ranges[key] | |||
return named_ratio_range ~= nil and named_ratio_range or key | |||
end | end | ||
function p.lookup_named_ancestor(input_mos) | function p.lookup_named_ancestor(input_mos) | ||
end | end | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 289: | Line 289: | ||
function p.tester() | function p.tester() | ||
--return p.lookup_step_ratio_range(rat.new(10, 1), rat.new(1, 0), true) | --return p.lookup_step_ratio_range(rat.new(10, 1), rat.new(1, 0), true) | ||
return p. | return p.lookup_step_ratio_range(rat.new(6,5), rat.new(1,1), true) | ||
end | end | ||
return p | return p | ||