Content deleted Content added
No edit summary |
add |
||
(2 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)
s = non_standard_abbreviations[s] or 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 = {}
Line 21 ⟶ 44:
v = mw.ustring.gsub(v, '^%s*[A-Z][^0-9]*%s([0-9].-)$', '%1')
-- team abbreviation
local abbr =
▲ abbr = mw.ustring.upper(abbr)
▲ abbr = mw.ustring.sub(abbr .. ' ', 1, 3)
if abbrevs[abbr] then
abbr = abbr .. k
|