Module:Sandbox/Frietjes/Rugby
-- This module may be used to assist with converting ascii tables to a rugby sports table
local p = {}
local non_standard_abbreviations = {
['HullIonians'] = 'ION',
['SheffieldTigers'] = 'TIG'
}
local function abbreviate(s)
s = mw.ustring.gsub(s, '%s', '')
s = non_standard_abbreviations[s] or s
s = mw.ustring.upper(s)
s = mw.ustring.sub(s .. ' ', 1, 3)
return s
end
function p.main(frame)
-- grab the input
local text = '\n' .. (frame.args[1] or '') .. '\n'
-- split into lines
local lines = mw.text.split(text, '[\r\n]')
-- join split lines
for k,v in ipairs(lines) do
if mw.ustring.match(v, '^%s*%d%d*%s*logo%s*') then
lines[k] = ''
if mw.ustring.match(lines[k+1] or '', '^%s*[A-Z][^0-9]*$') then
if mw.ustring.match(lines[k+2] or '', '^%s*[0-9]') then
lines[k+1] = lines[k+1] .. ' ' .. lines[k+2]
lines[k+2] = ''
end
end
end
end
-- hash to keep track of team abbreviations
local abbrevs = {}
-- strings to keep the result
local top, mid, bot = '| team_order = ', '', ''
-- process the input
local labels = {'', 'win', 'draw', 'loss', 'pf', 'pa', '', 'tb', 'lb', '', 'adjust_points'}
for k,v in ipairs(lines) do
if mw.ustring.match(v, '^%s*[A-Z][^0-9]*%s[0-9].-$') then
-- strip the team name from the line
local team = mw.ustring.gsub(v, '^%s*([A-Z][^0-9]*)%s[0-9].-$', '%1')
v = mw.ustring.gsub(v, '^%s*[A-Z][^0-9]*%s([0-9].-)$', '%1')
-- team abbreviation
local abbr = abbreviate(team)
if abbrevs[abbr] then
abbr = abbr .. k
else
abbrevs[abbr] = '1'
end
top = top .. abbr .. ', '
bot = bot .. '| name_' .. abbr .. ' = ' .. team .. '\n'
-- split the remainder
local stats = mw.text.split(v or 'ERROR', '%s%s*')
-- format stats
for j = 1,#labels do
if (labels[j] and labels[j] ~= '') then
if labels[j] == 'adjust_points' then
if (stats[j] and (0 ~= tonumber(stats[j])) ) then
mid = mid .. '| ' .. labels[j] .. '_' .. abbr .. ' = ' .. (stats[j] or '')
end
else
mid = mid .. '| ' .. labels[j] .. '_' .. abbr .. ' = ' .. (stats[j] or '')
end
end
end
mid = mid .. '\n'
end
end
top = mw.ustring.gsub(top, ',%s*$', '')
return '<pre>' .. top .. '\n\n' .. mid .. '\n' .. bot .. '</pre>'
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.
- 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:
- 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.
- 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.
- 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.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.