Module:Infobox rugby biography cleaner

local p = {}

local args = {}

local function isnotblank(s) return s and s:match( '^%s*(.-)%s*$' ) ~= '' end

local function argrename(n1, n2) if args[n1] or args[n2] then if( args[n1] and args[n1] ~=  ) and ( args[n2] and args[n2] ~=  ) then args[n2] = (args[n2] or '') .. '\n' .. (args[n1] or '') else args[n2] = (args[n2] or '') .. (args[n1] or '') end args[n1] = '' end end

local function addparam(s, f)	-- f = a, e, or nb	local r = '' if f == 'a' then r = '\n| ' .. s .. ' = ' .. (args[s] or '') elseif f == 'e' then if args[s] then r = '\n| ' .. s .. ' = ' .. args[s] end else if isnotblank(args[s]) then r = '\n| ' .. s .. ' = ' .. args[s] end end args[s] = '' return r end

local function addseries(s, n)	local r = '' local yname = s .. 'years' local cname = s .. 'clubs' local aname = s .. 'apps' local pname = s .. 'points' local showapps = true local showpts = true argrename(s .. 'caps', aname) for k=1,n do argrename(s .. 'caps' .. k, aname .. k)	end if (s == 'rl_youth') or (s == 'youth') then showapps = false showpts = false elseif (s == 'rl_club') then cname = 'rl_proclubs' elseif (s == 'city_vs_country_' or s == 'soo' or s == 'rl_national' 		or s == 'amat' or s == 'rep') then cname = s .. 'team' elseif ( s == 'ru_sevensnational' ) then cname = s .. 'team' aname = s .. 'comp' elseif (s == 'rl_coach' or s == 'ru_coach') then cname = s .. 'teams' showapps = false showpts = false elseif (s == 'rl_referee' or s == 'ru_referee') then cname = s .. 'comps' showpts = false elseif (s == 'ru_province') or (s == 'super') then cname = s	end if args[yname] and args[yname]:match('^[%s]*[%s]*$') then args[yname] = mw.ustring.gsub(args[yname], '^[%s]*[%s]*$', '%1') end if args[cname] and args[cname]:match('^[%s]*[%s]*$') then args[cname] = mw.ustring.gsub(args[cname], '^[%s]*[%s]*$', '%1') end if args[aname] and args[aname]:match('^[%s]*[%s]*$') then args[aname] = mw.ustring.gsub(args[aname], '^[%s]*[%s]*$', '%1') end if args[pname] and args[pname]:match('^[%s]*[%s]*$') then args[pname] = mw.ustring.gsub(args[pname], '^[%s]*[%s]*$', '%1') end if isnotblank(args[cname]) or isnotblank(args[yname]) then local ylist = mw.text.split(args[yname] or '', '[%s]*<[\/\t ]*[Bb][Rr][^<>]*>') local clist = mw.text.split(args[cname] or '', '[%s]*<[\/\t ]*[Bb][Rr][^<>]*>') local alist = {} local plist = {} if showapps then alist = mw.text.split(args[aname] or '', '[%s]*<[\/\t ]*[Bb][Rr][^<>]*>') end if showpts then plist = mw.text.split(args[pname] or '', '[%s]*<[\/\t ]*[Bb][Rr][^<>]*>') end if ((#clist) >= (#ylist)) and ((#clist) >= (#alist)) and ((#clist) >= (#plist)) then for k = 1,(#clist) do r = r .. '\n| ' .. yname .. k .. ' = ' .. (ylist[k] or '') r = r .. '\n| ' .. cname .. k .. ' = ' .. (clist[k] or '') if showapps then r = r .. '\n| ' .. aname .. k .. ' = ' .. (alist[k] or '') end if showpts then r = r .. '\n| ' .. pname .. k .. ' = ' .. (plist[k] or '') end end args[yname] = '' args[cname] = '' args[aname] = '' args[pname] = '' else r = r .. addparam(yname, 'e') r = r .. addparam(cname, 'e') r = r .. addparam(aname, 'e') r = r .. addparam(pname, 'e') end else r = r .. addparam(yname, 'e') r = r .. addparam(cname, 'e') r = r .. addparam(aname, 'e') r = r .. addparam(pname, 'e') end for k=1,n do r = r .. addparam(yname .. k, 'e') r = r .. addparam(cname .. k, 'e') r = r .. addparam(aname .. k, 'e') r = r .. addparam(pname .. k, 'e') end return r end

function p.main(frame) local res = '' local offset = 0 for k,v in pairs(frame.args) do		args[k] = v	end -- preprocess argrename('rl_coachclubs', 'rl_coachteams') argrename('ru_coachclubs', 'coachteams') argrename('ru_coachyears', 'coachyears') argrename('ru_youthclubs', 'youthclubs') argrename('ru_youthyears', 'youthyears') argrename('ru_amateurclubs', 'amatteam') argrename('ru_amateuryears', 'amatyears') argrename('ru_amateurcaps', 'amatcaps') argrename('ru_amateurpoints', 'amatpoints') argrename('ru_amupdate', 'amatupdate') argrename('ru_proclubs', 'clubs') argrename('ru_clubyears', 'years') argrename('ru_clubcaps', 'caps') argrename('ru_clubpoints', 'points') argrename('ru_clubupdate', 'clubupdate') argrename('super14', 'super') argrename('super14years', 'superyears') argrename('super14caps', 'supercaps') argrename('super14points', 'superpoints') argrename('super14update', 'superupdate') argrename('ru_nationalteam', 'repteam') argrename('ru_nationalyears', 'repyears') argrename('ru_nationalcaps', 'repcaps') argrename('ru_nationalpoints', 'reppoints') argrename('ru_ntupdate', 'repupdate') for k=1,10 do argrename('amatcaps' .. k, 'amatapps' .. k)	end res = res .. ''	return res end

return p