Module:SeasonVariables

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 06:49, 19 July 2023 by Vish (talk | contribs)
Jump to navigation Jump to search

Documentation for this module may be created at Module:SeasonVariables/doc

local p = {}

function p.main(frame)
    local input = frame.args[1]
    local abbreviations = {
        PB = "Phantom Blood",
        BT = "Battle Tendency",
        SC = "Stardust Crusaders",
        DU = "Diamond is Unbreakable",
        GW = "Golden Wind",
        SO = "Stone Ocean",
        SBR = "Steel Ball Run",
        JJL = "JoJolion",
        TJL = "The JOJOLands",
        ["TSKR Episode (%d+) %(OVA%)"] = "Thus Spoke Kishibe Rohan",
        ["(%w+) Episode (%d+): (.+)"] = function(abbreviation, episode_number, title)
            if string.find(title, ":") then
                return abbreviations[abbreviation] .. " Episode " .. episode_number .. ": " .. title
            else
                return abbreviations[abbreviation] .. " Episode " .. episode_number .. ": " .. title
            end
        end
    }
    for abbreviation, full_name in pairs(abbreviations) do
        local episode_number, title
        if type(full_name) == 'function' then
            abbreviation, episode_number, title = string.match(input, abbreviation)
            if abbreviation then
                return full_name(abbreviation, episode_number, title)
            end
        else
            episode_number = string.match(input, abbreviation .. " Episode (%d+)")
            if episode_number then
                return full_name .. " Episode " .. episode_number .. ": " .. string.sub(input, string.len(abbreviation) + string.len(" Episode ") + string.len(episode_number) + 1)
            end
        end
    end
    return input
end

return p