Modul:Runway
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 getArgs = require('Module:Arguments').getArgs
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
local function tableRow(orientation, geometry, surface)
local tr = mw.html.create('tr')
tr:tag('td'):wikitext(orientation)
tr:tag('td'):wikitext(geometry)
tr:tag('td'):wikitext(surface)
return tostring(tr)
end
local function listItem(orientation, geometry, surface)
return '\n* pista ' .. (orientation or '') .. (surface and ' din ' .. surface or '') .. (geometry and ', cu dimensiunile ' .. geometry or '')
end
local function stringPhrase(orientation, geometry, surface, runways)
if (runways > 2 ) then return listItem(orientation, geometry, surface) end
if surface or geometry then
return "Pista " .. (orientation or '') .. " are" .. (surface and " suprafața de " .. surface or "") .. ((surface and geometry) and " și" or "") .. (geometry and " dimensiunile " .. geometry or "") .. ". "
elseif orientation then
return "Pista are orientarea " .. orientation .. ". "
else
return ""
end
end
local function introduction(runways)
if (runways < 1) then return nil end
local endsign = ". "
if (runways > 2) then endsign = ': ' end
local number = runways .. " piste"
if (runways == 1) then number = "o singură pistă" end
return "Aeroportul dispune de " .. number .. endsign
end
p.fromArgs = function(q, output)
if output == nil then output = 'table' end
local runwayClaims = Wikidata.findBestClaimsForProperty(q, 'P529')
local runways = #runwayClaims
local rowtable = {}
if output == 'string' then table.insert(rowtable, introduction(runways)) end
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
if lengthQual and widthQual then
geometry = table.concat({table.concat({length, lUnit},mw.text.decode(' ')), table.concat({width, wUnit},mw.text.decode(' '))}, mw.text.decode(' × '))
end
end
if output == 'table' then
table.insert(rowtable, tableRow(orientation, geometry, surface))
elseif output == 'string' then
table.insert(rowtable, stringPhrase(orientation, geometry, surface, runways))
end
end
end
return table.concat(rowtable)
end
p.fromFrame = function(frame)
local args = getArgs(frame)
return p.fromArgs(args.q, args.output)
end
return p