Módulo:RaDec

Revisão em 01h20min de 14 de maio de 2024 por Jaewoo (discussão | contribs) (Criou a página com "--* Módulo para processar um ponto de ascensão reta ou declinação * * Imported from https://it.wikipedia.org/w/index.php?title=Modulo:RaDec&oldid=83380991 -- require('strict') local getArgs = require('Module:Arguments').getArgs local p = {} -- Funzione di utilità per altri moduli: -- parsifica il testo generato dal Template:RA (ascensione retta) e -- restituisce una table con chiavi 'h', 'm' e 's' di tipo number. function p.parseRA(text) local h, m, s...")
(dif) ← Revisão anterior | Revisão atual (dif) | Revisão seguinte → (dif)

A documentação para este módulo pode ser criada na página Módulo:RaDec/doc

--[[
* Módulo para processar um ponto de ascensão reta ou declinação
*
* Imported from https://it.wikipedia.org/w/index.php?title=Modulo:RaDec&oldid=83380991
]]--
require('strict')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Funzione di utilità per altri moduli:
-- parsifica il testo generato dal Template:RA (ascensione retta) e
-- restituisce una table con chiavi 'h', 'm' e 's' di tipo number.
function p.parseRA(text)
				local h, m, s
				text = mw.text.trim(mw.text.unstrip(text)):gsub('−', '-'):gsub(',', '.')
				h, m, s = text:match('^(%d+)<sup>h</sup>&nbsp;(%d+)<sup>m</sup>&nbsp;([%d%.]+)<sup>s</sup>$')
				if not h then
								h, m = text:match('^(%d+)<sup>h</sup>&nbsp;(%d+)<sup>m</sup>&nbsp;:$')
								s = 0
				end
				if not h then
								h = text:match('^(%d+)<sup>h</sup>&nbsp;:$')
								m, s = 0, 0
				end
				h, m, s = tonumber(h), tonumber(m), tonumber(s)
				return (h and m and s) and { h = h, m = m, s = s } or nil
end
-- Funzione di utilità per altri moduli:
-- parsifica il testo generato dal Template:DEC (declinazione) e
-- restituisce una table con chiavi 'd', 'm' e 's' di tipo number.
function p.parseDEC(text)
				local d, m, s
				text = mw.text.trim(mw.text.unstrip(text)):gsub('−', '-'):gsub(',', '.')
				d, m, s = text:match('^([+-]?%d+)&deg;&nbsp;(%d+)&prime;&nbsp;([%d%.]+)&Prime;$')
				if not d then
								d, m = text:match('^([+-]?%d+)&deg;&nbsp;(%d+)&prime;&nbsp;:$')
								s = 0
				end
				if not d then
								d = text:match('^([+-]?%d+)&deg;&nbsp;:$')
								m, s = 0, 0
				end
				d, m, s = tonumber(d), tonumber(m), tonumber(s)
				return (d and m and s) and { d = d, m = m, s = s } or nil
end
-- Entry-point per il template {{RA}}
function p.RA(frame)
				local args = getArgs(frame, { parentOnly = true })
				local h, m, s = args[1] and (args[1] .. '<sup>h</sup>&nbsp;') or '', args[2] or ':', args[3] or ':'
				m = m .. (m == ':' and '' or '<sup>m</sup>&nbsp;')
				s = s .. (s == ':' and '' or '<sup>s</sup>')
				return h .. m .. (m == ':' and '' or s)
end
-- Entry-point per il template {{DEC}}
function p.DEC(frame)
				local args = getArgs(frame, { parentOnly = true })
				local d, m, s = args[1] and (args[1] .. '&deg;&nbsp;') or '', args[2] or ':', args[3] or ':'
				m = m .. (m == ':' and '' or '&prime;&nbsp;')
				s = s .. (s == ':' and '' or '&Prime;')
				return d .. m .. (m == ':' and '' or s)
end
return p