Module:Stats/doc

-- NB: Depends on and  ; use  instead of invoking this module directly. -- &lt;nowiki&gt; local p = {}

local data = mw.loadData('Module:Stats/data') local ranks = { ['S+'] = '6', ['S' ] = '6', ['S-'] = '6', ['A+'] = '5', ['A' ] = '5', ['A-'] = '5', ['B+'] = '4', ['B' ] = '4', ['B-'] = '4', ['C+'] = '3', ['C' ] = '3', ['C-'] = '3', ['D+'] = '2', ['D' ] = '2', ['D-'] = '2', ['E+'] = '1', ['E' ] = '1', ['E-'] = '1', ['?' ] = '?' }

function p.render(frame) -- NB: Ideally we'd use the frontier pattern (like `^%f[%u].*%a$`), --    but `mw.ustring` is missing the [backport]( https://github.com/Wikia/app/pull/15769 ). local full_name = assert(mw.ustring.match(frame.args[1], '^%u.*%a$')) local stats = assert(data[full_name]) assert(type(stats[1]) == 'boolean')

local short_name = stats[1] and assert(mw.ustring.match(full_name, '^[^%s]+')) or full_name local fragments = {}

if type(stats[2]) == 'table' then local length = 0 for i, v in ipairs(stats[2]) do if i <= 5 then assert(mw.ustring.match(stats[2][i], '^[SABCDE?]$')) end length = length + 1 end assert(length == 5) table.insert(fragments, {'Ultra Archive', ' '}) end

if type(stats[3]) == 'table' then local length = 0 for i, v in ipairs(stats[3]) do if i <= 5 then assert(mw.ustring.match(stats[3][i], '^[SABCDE][+-]?$') or stats[3][i] == '?') end length = length + 1 end assert(length == 6) assert(mw.ustring.match(stats[3][6], '^%u.*%a$')) table.insert(fragments, {'Ultra Analysis', ' '}) end

local wikitext if #fragments == 0 then return '' elseif #fragments == 1 then wikitext = fragments[1][2] else wikitext = ' \n ' for i, v in ipairs(fragments) do wikitext = wikitext .. (i > 1 and '|-|\n ' or '' ) .. v[1] .. '=' .. v[2] .. '\n ' end wikitext = wikitext .. ' ' end return frame:preprocess(wikitext) end

return p -- &lt;/nowiki&gt;