Module:Sandbox/Frietjes/Rugby: Difference between revisions

Content deleted Content added
No edit summary
add
 
(6 intermediate revisions by the same user not shown)
Line 1:
-- 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)
abbr s = mw.ustring.subgsub(abbr ..s, ' %s', 1, 3'')
s = non_standard_abbreviations[s] or s
abbr s = mw.ustring.upper(abbrs)
s = mw.ustring.sub(s .. ' ', 1, 3)
return s
end
 
function p.main(frame)
-- splitgrab the text into linesinput
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'}
Line 18 ⟶ 44:
v = mw.ustring.gsub(v, '^%s*[A-Z][^0-9]*%s([0-9].-)$', '%1')
-- team abbreviation
local abbr = mw.ustring.gsubabbreviate(team, '%s', '')
abbr = mw.ustring.upper(abbr)
abbr = mw.ustring.sub(abbr .. ' ', 1, 3)
if abbrevs[abbr] then
abbr = abbr .. k
Line 26 ⟶ 50:
abbrevs[abbr] = '1'
end
top = top .. abbr .. ', '
bot = bot .. '| name_' .. abbr .. ' = ' .. team .. '\n'
-- split the remainder
Line 32 ⟶ 57:
for j = 1,#labels do
if (labels[j] and labels[j] ~= '') then
if (labels[j] == 'adjust_points' andthen
if (stats[j] and (0 ~= tonumber(stats[j])) ~= '0') then
top mid = topmid .. '| ' .. labels[j] .. '_' .. abbr .. ' = ' .. (stats[j] or '')
end
else
topmid = topmid .. '| ' .. labels[j] .. '_' .. abbr .. ' = ' .. (stats[j] or '')
end
end
end
topmid = topmid .. '\n'
end
end
returntop '<pre>'= mw.ustring. gsub(top .., '\n,%s*$' .. bot .., '</pre>')
return '<pre>' .. top .. '\n\n' .. mid .. '\n' .. bot .. '</pre>'
end