Modulo:Infobox nave: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
Moroboshi (discussione | contributi)
fix round
Moroboshi (discussione | contributi)
+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^idppow
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]]"
end
return '<sup class="error">' .. msg .. '</sup>'
end
 
---============================================================
Line 70 ⟶ 96:
else
local kmh = tonumber(spd_kmh)
if kmh then
spd_kn = sep_thousand(tostring(round_auto(kmh/1.852)))
end
end
end
local out_kn = spd_kn and (spd_kn .. "&nbsp;[[Nodo (unità di misura)|nodi]]")
local out_kmh = spd_kmh and (spd_kmh .. "&nbsp;[[Chilometro orario|km/h]]" )
Line 88 ⟶ 114:
end
 
local function format_m(m1_raw, m2_raw, factor, measure_type, m1_unit, m2_unit, check_errorignore_error)
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 --.. add_error(check_errorignore_error, "La " .. m_type .. "deve essere andespressa error_messagecon orun ''numero")
end
if m2_value then
m2_formatted = format_value(tostring(m2_value))
elseif m2_raw then
m2_formatted = m2_raw --.. add_error(check_errorignore_error, and"La error_message" or.. m_type .. "deve essere espressa con un ''numero")
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, "&nbsp; [[Miglio nautico|miglia]]" )
Line 140 ⟶ 158:
end
if km_formatted then
if kn_formatted then dump(out, " (") end
dump(out, "km_formatted, ("&nbsp;[[chilometro|km]]" )
end
dump(out, km_formatted, "&nbsp; [[chilometro|km]]" )
if kmh_formatted then
dump(out, " a ", kmh_formatted, "&nbsp;[[chilometro orario|km/h]]")
end
if kn_formated then
dump (out, ")")
end
if kn_formatted then dump (out, ")") end
end
return table.concat(out)