Modul:Runway

De la Wikipedia, enciclopedia liberă

Documentația acestui modul poate fi creată la Modul:Runway/doc

local p = {}
local Wikidata = require('Modul:Wikidata')
local formatNum = require('Modul:Formatnum')._formatNum

local function extractAbbrevFromURL(url)
	local unitQ = mw.ustring.match(url, 'Q%d+')
	if not unitQ then return nil end
	return Wikidata.findLanguageText('P5061', 'ro', unitQ) or Wikidata.findLabel(unitQ)
end

p.fromArgs = function(q)
	local runwayClaims = Wikidata.findBestClaimsForProperty(q, 'P529')
	local rowtable = {}
	for _,eachRunwayClaim in ipairs(runwayClaims) do
		if eachRunwayClaim.type == 'statement' and eachRunwayClaim.mainsnak and eachRunwayClaim.mainsnak.snaktype == 'value' then
			local orientation = eachRunwayClaim.mainsnak.datavalue.value
			local geometry
			local surface
			
			if eachRunwayClaim.qualifiers then
				local surfaceQual = eachRunwayClaim.qualifiers['P186']
				if surfaceQual then for _,actualSurfaceQual in ipairs(surfaceQual) do
					surface = actualSurfaceQual and actualSurfaceQual.snaktype == 'value' and Wikidata.printSnak(actualSurfaceQual) or nil
				end end

				local lengthQual = eachRunwayClaim.qualifiers['P2043']
				local widthQual = eachRunwayClaim.qualifiers['P2049']
				
				local lUnit
				local wUnit
				local length
				local width
				if lengthQual then for _,actualLengthQual in ipairs(lengthQual) do
					length = formatNum(tostring(tonumber(actualLengthQual.datavalue.value.amount)))
					lUnit = unit or extractAbbrevFromURL(actualLengthQual.datavalue.value.unit)
				end end
				if widthQual then for _,actualWidthQual in ipairs(widthQual) do
					width = formatNum(tostring(tonumber(actualWidthQual.datavalue.value.amount)))
					wUnit = unit or extractAbbrevFromURL(actualWidthQual.datavalue.value.unit)
				end end
				geometry = table.concat({table.concat({length, lUnit},mw.text.decode(' ')), table.concat({width, wUnit},mw.text.decode(' '))}, mw.text.decode(' × '))
			end
			
			local tr = mw.html.create('tr')
			tr:tag('td'):wikitext(orientation)
			tr:tag('td'):wikitext(geometry)
			tr:tag('td'):wikitext(surface)
			table.insert(rowtable, tostring(tr))
		end
	end
	return table.concat(rowtable)
end


p.fromFrame = function(frame)
	return p.fromArgs(frame.args.q)
end

return p