Module:Sandbox/ProcrastinatingReader/ib

This is an old revision of this page, as edited by ProcrastinatingReader (talk | contribs) at 13:05, 5 December 2020. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local getArgs = require('Module:Arguments').getArgs

local p = {}

local function isempty(s)
  return s == nil or s == ''
end

local function dataValue(frame, settlementName, parameterName, itemName)
	return frame:expandTemplate{ title = 'Data '..settlementName..' municipality', args = {
		parameterName,
		itemName
	}}
end

local function getNetValue(frame, argName)
	local args = getArgs(frame)
	local argType = args['arg_type'] and (args['arg_type']..'_') or ''
	local paramName = 'area_'..argType..argName

	local net = args[paramName] or dataValue(frame, args['subdivision_name'], paramName, args['name'])

	return net
end

function p.nativeName(frame)
	local val = frame.args[1]
	
	if val then
		local match = mw.ustring.match(val, "{{[Ii]nfobox (%a*)")
		--if true then return match end
		if match and match[1] then
			return match[1]
		end
	end
	
	return ""
end

function p.area(frame)
	local args = getArgs(frame)
	
	local km2 = getNetValue(frame, 'km2')
	local ha = getNetValue(frame, 'ha')
	local acre = getNetValue(frame, 'acre')
	local sqmi = getNetValue(frame, 'sq_mi')
	local dunam = getNetValue(frame, 'dunam')
	
	if not (isempty(km2) and isempty(ha) and isempty(acre) and isempty(sqmi) and isempty(dunam)) then
		return frame:expandTemplate{ title = 'infobox_settlement/areadisp', args = {
			['km2'] = km2,
			['ha'] = ha,
			['acre'] = acre,
			['sqmi'] = sqmi,
			['dunam'] = dunam,
			['link'] = args['dunam_link'],
			['pref'] = args['unit_pref'],
			['name'] = args['subdivision_name'],
			['mag'] = args['area_magnitude']
		}}
	else
		return ""
	end
end

function p.generic(frame)
	local args = getArgs(frame)
	local argType = args['arg_type']
	
	return getNetValue(frame, argType)
end

return p