Module:Ep/Matcher

local p = {};

-- for converting Ep/Array array into pairs of input string:output episode code make_query_pairs = function local epInfos = mw.loadData('Module:Ep/Array') query_pairs = {} for k, v in pairs(epInfos) do       query_pairs[k:lower] = k        for key, val in pairs(v) do            if type(val) == 'string' then query_pairs[val:lower] = k           else for i, option in pairs(val) do                   query_pairs[option:lower] = k            end end end end return query_pairs end

-- use the query pairs to match any input string to the formatted episode code p.matchCode = function(frame) local ep_string = frame.args[1] ep = ep_string:lower query_pairs = make_query_pairs if query_pairs[ep] then episode_code = query_pairs[ep] else episode_code = '0x00' end return episode_code end

return p