Module:Fiction-based redirects to list entries category handler/RedirectType

local libraryUtil = require('libraryUtil')

local p = {}

local franchiseList = { [1] = "Module:Arrowverse redirect category handler" }

-- RedirectType class. -- local function RedirectType(o) local RedirectType = o or {redirectType = "", defaultCategory = "", topLevelCategory = "", template = "", from = "", suffix = "", isFranchise = false} local checkSelf = libraryUtil.makeCheckSelfFunction('Fiction-based redirects to list entries category handler', 'RedirectType', RedirectType, 'Fiction-based redirects to list entries category handler object')

-- Public function which is used to retrieve the main category for a specific type. -- function RedirectType:getMainCategory(mainCategory) return RedirectType:getCategory(mainCategory) end -- Public function which is used to retrieve the top level category (or categories) for a specific type and media format. If no media format is passed, the function returns the default top level category. -- function RedirectType:getTopLevelCategory(mediaList) if (mediaList and #mediaList &#x3e; 0) then local categories = "" for i = 1, #mediaList do				local category if ((RedirectType.redirectType == "episode") and (string.lower(mediaList[i]) == "television")) then category = RedirectType:getCategory(RedirectType.defaultCategory) else category = RedirectType:getCategory(RedirectType.topLevelCategory) end categories = categories .. category:gsub("{media}", mediaList[i]) end return categories else return RedirectType.defaultCategory end end

-- Public function which is used to retrieve a category for a specific type. -- function RedirectType:getCategory(category) return category:gsub("{type}", RedirectType.redirectType) end

-- Public function which is used to check if the category belongs to a special franchise, such as the Arrowverse. If the category is part of that franchise, returns the series name, else returns nil. -- function RedirectType:isCategorySpecialFranchise(series) local seriesParameter if (RedirectType.redirectType == "character" or RedirectType.redirectType == "element" or RedirectType.redirectType == "location") then for i, v in pairs(franchiseList) do				local seriesModule = require(v) local seriesList = seriesModule.getSeriesList for i, v in pairs(seriesList) do					local currentTVSeries = seriesList[i] if (series == currentTVSeries.seriesName) then seriesParameter = currentTVSeries.argName break end end local franchise = seriesModule.getFranchiseName if (series == franchise) then seriesParameter = franchise RedirectType.isFranchise = true end if (seriesParameter) then if (i == 1) then RedirectType:setTemplateAsArrowverse end break end end end if (seriesParameter) then return seriesParameter else return nil end end

-- Public function which is used to change the type of template to the Arrowverse specific version. -- function RedirectType:setTemplateAsArrowverse RedirectType.template = "Arrowverse " .. RedirectType.redirectType .. " redirect" end

return RedirectType end

-- Public function which is used to retrieve the list of redirect types. -- function p.getRedirectTypes return { RedirectType{ redirectType = "character", defaultCategory = "", topLevelCategory = "", template = "Fictional character redirect", from = "fictional characters", suffix = "redirects to lists" },		RedirectType{ redirectType = "element", defaultCategory = "", topLevelCategory = "", template = "Fictional element redirect", from = "fictional elements", suffix = "redirects to lists" },		RedirectType{ redirectType = "episode", defaultCategory = "", topLevelCategory = "", template = "Television episode redirect handler", from = "episodes", suffix = "redirects to lists" },		RedirectType{ redirectType = "location", defaultCategory = "", topLevelCategory = "", template = "Fictional location redirect", from = "fictional locations or settings", suffix = "redirects" }	}

end

-- Public function which is used to retrieve a default redirect type. -- function p.getDefaultType(typeList) return typeList[3] end

return p