Content deleted Content added
m Johnuniq moved page Module:WeatherBox to Module:Weather box/row without leaving a redirect: name consistent with Template:Weather box and to show that this submodule handles one row in a weather box |
require submodule + implement "trace" per request at talk |
||
Line 1:
local w = {}
local math_mod = require(
local wbc = require(
local traceText
local Value
Value = {
lang = mw.getContentLanguage(),
getDisplay = function (self, second)
if not self:isValid() then
return nil
end
local display = self.string
if display == 'trace' then
if second then
-- If a cell displays "cm (inch)", show "trace" not "trace (trace)".
return nil
end
return traceText or 'trace'
end
if math.abs(self.number) >= 1000 then
display = self.lang:formatNum(math.abs(self.number))
Line 37 ⟶ 45:
end,
new = function (v)
local val, str, precision
if type(v) == 'string' then
if v == 'trace' then
val, str = math_mod._cleanNumber(v)▼
val, str, precision = 0, 'trace', 0
else
▲ val, str = math_mod._cleanNumber(v)
end
elseif type(v) == 'number' then
val, str = v, tostring(v)
Line 49 ⟶ 61:
number = val,
string = str,
precision = precision,
}, Value)
end,
Line 59 ⟶ 72:
setConvert = function (self, invalue, units)
-- Use method modified from [[Module:Convert]] to determine precision.
if invalue.string == 'trace' then
self.number, self.string, self.precision = 0, 'trace', 0
return
end
local convert = self.converts[units] or error('Unknown units')
local outnum = invalue.number * convert.factor
Line 122 ⟶ 139:
table.insert( result, display )
if second_values ~= nil then
display = second_values[i]:getDisplay(true)
if display then
table.insert( result, "<br />(" .. display .. ")" )
Line 306 ⟶ 323:
local metric_first = checkFlag( frame.args['metric first'] or pframe.args['metric first'] )
local single_line = checkFlag( frame.args['single line'] or pframe.args['single line'] )
local trace = pframe.args.trace
if trace and trace ~= '' then
traceText = trace
end
if imperial_first == nil then
|