Modulo:RaDec

Info Istruzioni per l'uso
Questo è un modulo scritto in Lua. Le istruzioni che seguono sono contenute nella sottopagina Modulo:RaDec/man (modifica · cronologia)
Sandbox: Modulo:RaDec/sandbox (modifica · cronologia) · Sottopagine: lista · Test: Modulo:RaDec/test

Modulo che implementa i template {{RA}} e {{DEC}}.

Contiene inoltre funzioni di parsing del loro output per i moduli (parseRA e parseDEC), in modo da tenere allineato il formato nella generazione e nel parsing.



--[[
* Modulo che implementa i template RA e DEC, con inoltre funzioni di parsing del loro output,
* in modo da tenere allineato il formato nella generazione e nel parsing.
]]--

require('strict')

local getArgs = require('Modulo: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 'sign', 'd', 'm' e 's' di tipo number.
function p.parseDEC(text)
	local sign, d, m, s

	text = mw.text.trim(mw.text.unstrip(text)):gsub('&#43;', '+'):gsub('&#45;', '-'):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)
	if d then
		sign = (d < 0 or tostring(d) == '-0') and -1 or 1
		d = math.abs(d)
	end

	return (sign and d and m and s) and { sign = sign, 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 ':'
	d = mw.text.encode(d, '+-')
	m = m .. (m == ':' and '' or '&prime;&nbsp;')
	s = s .. (s == ':' and '' or '&Prime;')
	return d .. m .. (m == ':' and '' or s)
end

return p

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.