local data = mw.loadData ('Module:USN fleet totals/data'); -- get the detailed list of ship types and their counts, the grand total of active and reserve ships, and the total planned shipslocal get_args = require ('Module:Arguments').getArgs;
----------------------------< R O U N D >--------------------------------------------------------------------
rounds
local function round (count) if 0
--active}} planned – the 'planned total' (ships under construction or on order) rounded to the nearest multiple of 5 -- retire – number of ships to be decommissioned or taken out of service -- retire-year – planned retirement year farthest in the future --
local function USN_fleet_totals (frame) if 'active'
frame.args[1] then -- under construction and on-order ships return round (data.planned_total); -- round to nearest multiple of 5 elseif 'retire'
frame.args[1] then return data.retirements_year_max; else -- is anything else return data.fleet_totals_str; -- return the detailed fleet totals endend
----------------------------< _ D E C O M _ E O S _ C O M M O N >--------------------------------------------
common function to implement and templates
local function _decom_eos_common (args_t, phrases_t, template_name) local out_t = ;
if phrases_t[args_t[1]] then -- is keyword valid? table.insert (out_t, phrases_t[args_t[1]]); -- yes, get the associated string elseif args_t[1] then -- no, but not nil so emit appropriate error message return '
: error: unknown keyword: ' .. args_t[1] .. ''; else -- missing keyword so emit error message return ': error: missing keyword' endif args_t[2] then -- did we get this optional parameter? local year = mw.text.trim (args_t[2]):match ('^%d%d%d%d$'); -- attempt to get a four digit year
if year then -- did we find a 'year'? TODO: validate? must be this or a future year? never in the past? table.insert (out_t, year); -- add the year to the output else -- here when a four-digit 'year' not found return '
: error: invalid year'; end endreturn table.concat (out_t, ' '); -- assemble into a big string and doneend
--
local function decommission (frame) local args_t = get_args (frame); -- get parameters from the template into a local table return _decom_eos_common (args_t, data.decommission_t, 'decommission'); -- call common function to error check the inputs and return the rendered stringend
--
local function end_of_service (frame) local args_t = get_args (frame); -- get parameters from the template into a local table return _decom_eos_common (args_t, data.end_of_service_t, 'end of service'); -- call common function to error check the inputs and return the rendered stringend
----------------------------< E X P O R T S >----------------------------------------------------------------
return