Modulo:Infobox nave: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
fix round |
+commenti, fix bug minori, categoria di errore |
||
Riga 2:
local getArgs = require('Module:Arguments').getArgs
---============================================================
-- Save argument in table
---============================================================
local function dump(t, ...)
local args = {...}
Line 15 ⟶ 18:
local pow = idp or 0
if idp then
local mult = 10^
local adder = (num >= 0 and 0.5) or -0.5
return math.floor(num * mult + adder) / mult
Line 44 ⟶ 47:
end
---============================================================
-- Convert string to number ("," are considered as ".")
---============================================================
local function get_value(s)
if s then
Line 51 ⟶ 57:
end
---============================================================
-- Format a number as string replacin "." with "," and adding
-- no breaking space as separator between thousands
---============================================================
local function format_value(value)▼
if value then▼
local s = tostring(value)▼
s = s:gsub("%.", ",")▼
return sep_thousand(s)▼
end▼
end▼
local function add_error(ignore_error, msg)
if ignore_error then return '' end
local current_page = mw.title.getCurrentTitle()
if current_page.namespace == 0 then
msg = msg .. "[[Categoria:Errori di compilazione del template Infobox nave]]"
return '<sup class="error">' .. msg .. '</sup>'
---============================================================
Line 70 ⟶ 96:
else
local kmh = tonumber(spd_kmh)
end
local out_kn = spd_kn and (spd_kn .. " [[Nodo (unità di misura)|nodi]]")
local out_kmh = spd_kmh and (spd_kmh .. " [[Chilometro orario|km/h]]" )
Line 88 ⟶ 114:
end
local function format_m(m1_raw, m2_raw, factor, measure_type, m1_unit, m2_unit,
▲local function format_value(value)
▲ if value then
▲ local s = tostring(value)
▲ s = s:gsub("%.", ",")
▲ return sep_thousand(s)
▲ end
▲end
▲local function format_m(m1_raw, m2_raw, factor, measure_type, m1_unit, m2_unit, check_error)
if not (m1_raw or m2_raw) then
return
Line 112 ⟶ 130:
m1_formatted = format_value(tostring(m1_value))
elseif m1_raw then
m1_formatted = m1_raw
end
if m2_value then
m2_formatted = format_value(tostring(m2_value))
elseif m2_raw then
m2_formatted = m2_raw
end
return m1_formatted, m2_formatted
end
function p.range(frame)
Line 133 ⟶ 150:
local nmi_formatted, km_formatted = format_m(range_nmi, range_km, 0.539957, "distanza", "miglia marine", "km")
local kn_formatted, kmh_formatted = format_m(range_kn, range_kmh, 1.852, "velocità", "nodi", "km/h")
if range_type then dump(out, range_type, ":") end
if nmi_formatted then
dump(out, nmi_formatted, " [[Miglio nautico|miglia]]" )
Line 140 ⟶ 158:
end
if km_formatted then
if kn_formatted then dump(out, " (") end
▲ end
if kmh_formatted then
dump(out, " a ", kmh_formatted, " [[chilometro orario|km/h]]")
▲ end
dump (out, ")")▼
end
end
return table.concat(out)
|