Difference between revisions of "Module:Sandbox/Ahecht/Cite DNV"
< Module:Sandbox | Ahecht
Jump to navigation
Jump to search
blackwiki>Ahecht (vesselid and register parsing) |
blackwiki>Ahecht (shipname) |
||
| Line 12: | Line 12: | ||
end | end | ||
| − | + | url, vesselid = string.match(string.lower(args['url']),'//exchange.dnv.com/exchange/main.aspx?(.*)vesselid=(g?%d%d%d%d%d%d?)') | |
| − | + | vesselid = vesselid or string.lower((args['id'] or args['ID']) or args['vesselid']) | |
| − | + | if not vesselid then | |
| − | + | success=false | |
| − | + | elseif not tonumber(vesselid) then | |
| − | + | vesselid = string.upper(vesselid) | |
| − | + | register = "GL" | |
| − | + | elseif vesselid > 99999 then | |
| − | + | vesselid = "G"..vesselid | |
| − | + | register = "GL" | |
end | end | ||
| + | |||
| + | shipname = (string.match(args['title'],'\'\'(.-)\'\'') or args['title']) or (args['shipname'] or args['name']) | ||
| + | if not shipname then success=false end | ||
return '{{cite ship register|register='..register..'|id='..vesselid..'|shipname='..(string.match(args['title'],'\'\'(.-)\'\'') or args['title'])..'|accessdate='..((args['accessdate'] or args['access-date']) or '') | return '{{cite ship register|register='..register..'|id='..vesselid..'|shipname='..(string.match(args['title'],'\'\'(.-)\'\'') or args['title'])..'|accessdate='..((args['accessdate'] or args['access-date']) or '') | ||
Revision as of 16:14, 17 May 2016
Documentation for this module may be created at Module:Sandbox/Ahecht/Cite DNV/doc
local p = {}
local htmlerror = require('Module:Error').error
function p.citednv(frame)
local origArgs = frame:getParent().args
local args = {}
local success=true
local register="DNV"
for k, v in pairs(origArgs) do
args[k] = v
end
url, vesselid = string.match(string.lower(args['url']),'//exchange.dnv.com/exchange/main.aspx?(.*)vesselid=(g?%d%d%d%d%d%d?)')
vesselid = vesselid or string.lower((args['id'] or args['ID']) or args['vesselid'])
if not vesselid then
success=false
elseif not tonumber(vesselid) then
vesselid = string.upper(vesselid)
register = "GL"
elseif vesselid > 99999 then
vesselid = "G"..vesselid
register = "GL"
end
shipname = (string.match(args['title'],'\'\'(.-)\'\'') or args['title']) or (args['shipname'] or args['name'])
if not shipname then success=false end
return '{{cite ship register|register='..register..'|id='..vesselid..'|shipname='..(string.match(args['title'],'\'\'(.-)\'\'') or args['title'])..'|accessdate='..((args['accessdate'] or args['access-date']) or '')
end
return p