Jump to content

Module:WPSHIPS utilities

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 15:48, 7 September 2015 (Create;). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('Module:No globals')

local wpsu={}


--[[-------------------------< S H I P  P R E F I X   L I S T >-----------------------------------------------

This is a list of currently supported ship prefixes.  To add to this list the form is:
	['prefix'] = length,
the trailing comma is important and of course, the prefix length must match the number of characters actually in
the prefix.

]]

local ship_prefix_list =
	{
	['ARA'] = 3,		-- Armada de la República Argentina
	['ARC'] = 3,		-- Armada Nacional de la República de Colombia
	['CCGS'] = 4,		-- Canadian Coast Guard Ship
	['CFAV'] = 4,		-- Canadian Forces Auxiliary Vessel
	['CS'] = 2,			-- Cable Ship
	['CSS'] = 3,		-- Confederate States Ship
	['FGS'] = 3,		-- Federal German Ship
	['GTS'] = 3,		-- Gas Turbine Ship
	['HDMS'] = 4,		-- His/Her Danish Majesty's Ship
	['HMAS'] = 4,		-- Her/His Majesty's Australian Ship
	['HMBS'] = 4,		-- Her/His Majesty's Britannic Ship (also: Bahamian, Bermudian, Burmese)
	['HMC'] = 3,		-- Her/His Majesty's Cutter
	['HMCS'] = 4,		-- Her/His Majesty's Canadian Ship (also Colonial)
	['HMNZS'] = 5,		-- Her/His Majesty's New Zealand Ship
	['HMQS'] = 4,		-- Her/His Majesty's Queensland Ship
	['HMS'] = 3,		-- Her/His Majesty's Ship
	['HMT'] = 3,		-- Her/His Majesty's Trawler
	['HMVS'] = 4,		-- Her/His Majesty's Victorian Ship
	['HNLMS'] = 5,		-- His/Her Netherlands Majesty’s Ship
	['HNoMS'] = 5,		-- His/Her Norwegian Majesty's Ship
	['HSwMS'] = 5,		-- His/Her Swedish Majesty's Ship
	['HTMS'] = 4,		-- His Thai Majesty's Ship
	['INS'] = 3,		-- Indian Naval Ship, Israeli Naval Ship
	['KDM'] = 3,		-- Kongelige Danske Marine
	['MF'] = 2,			-- Motor Ferry
	['MS'] = 2,			-- Motor Ship
	['MV'] = 2,			-- Motor Vessel
	['NoCGV'] = 5,		-- Norwegian Coast Guard Vessel
	['NRP'] = 3,		-- Navio da República Portuguesa
	['ORP'] = 3,		-- Okręt Rzeczypospolitej Polskiej
	['PS'] = 2,			-- Paddle Steamer
	['RFA'] = 3,		-- Royal Fleet Auxiliary
	['RNLB'] = 4,		-- Royal National Lifeboat
	['RMAS'] = 4,		-- Royal Maritime Auxiliary Service
	['RMS'] = 3,		-- Royal Mail Ship
	['RV'] = 2,			-- Research Vessel
	['SM'] = 2,			-- Seiner Majestät Unterseeboot
	['SMS'] = 3,		-- Seiner Majestät Schiff
	['SS'] = 2,			-- Screw Steamer or Steamship
	['TCG'] = 3,		-- Türkiye Cumhuriyeti Gemisi
	['TV'] = 2,			-- Training vessel
	['USAFS'] = 5,		-- United States Air Force ship
	['USAS'] = 4,		-- United States Army Ship
	['USCGC'] = 5,		-- United States Coast Guard Cutter
	['USNS'] = 4,		-- United States Naval Ship
	['USRC'] = 4,		-- United States Revenue Cutter
	['USS'] = 3,		-- United States Ship
	}

--[[--------------------------< I S _ S E T >------------------------------------------------------------------

Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.

]]
local function is_set( var )
	return not (var == nil or var == '');
end


--[[-------------------------< S H I P _ N A M E _ F O R M A T >----------------------------------------------

This function applies correct styling to free-form ship names.  These names are, for example, ship-article titles
used by templates {{navsource}}, {{Infobox ship begin}}, where the article title is to be rendered with proper
styling.

This function takes a single argument, the ship name, perhaps like this:
	{{#invoke:WPSHIPS_utilities|ship_name_format|name={{PAGENAME}}}}

]]
function wpsu.ship_name_format(frame)
--	local pframe = frame:getParent()											-- is this needed?
--	local args = {};
--
--	for k, v in pairs( pframe.args ) do
--		args[k] = v;
--	end

	if not is_set (frame.name) then return '' end;									-- return an empty string if there is no name
	
	local prefix = '';
	local name = '';
	local dab = '';
	
	if frame.name:match (arg, '^%s*%S*%s+.+%s+%b()%s*$') then					-- if name might have a prefix
		prefix, name, dab = frame.name:match (arg, '^%s*(%S*)%s+(.+)%s+(%b())%s*$');	-- get the component parts
		if ship_prefix_list [prefix] then
			name = ship_prefix_list [prefix] .. " ''" .. name .. "'' " .. dab;	-- assemble formatted name
		end
	elseif frame.name:match (arg, '^%s*.+%s+%b()%s*$') then						-- if name might not have a prefix
		name, dab = frame.name:match (arg, '^%s*(.+)%s+(%b())%s*$');			-- get the component parts
		name = " ''" .. name .. "'' " .. dab;									-- assemble formatted name
	end
	return name;																-- return the formatted name
end

return wpsu;