پودمان:Infobox road/abbrev/CAN
ظاهر
local p = {}
local format = mw.ustring.format
local typesModule = require "Module:Infobox road/abbrev/defs"
Country = typesModule.Country
Type = typesModule.Type
Abbr = typesModule.Abbr
local abbrs = Country:new()
do -- Abbreviation definitions
function abbrs:typeOverride(args)
local type = args.type
local province = args.province
if type == province then
return self["Hwy"]
else
return nil
end
end
do -- Provincial highways
local type = Type:new()
do
local types = {"Fwy", "Hwy", "PTH", "Route"}
for i,v in ipairs(types) do
abbrs[v] = type
end
end
do -- Hwy
local abbr = Abbr:new{formatStr = "Hwy %s"}
type["AB"] = abbr
type["YT"] = abbr
type["SK"] = abbr
type["NT"] = abbr
end -- Hwy
do -- Route
local provinces = {"QC", "NB", "PE", "NL"}
local abbr = Abbr:new{formatStr = "Route %s"}
for i,v in ipairs(provinces) do
type[v] = abbr
end
end -- Route
type["BC"] = Abbr:new{formatStr = "BC %s"}
type["MB"] = Abbr:new{formatStr = "PTH %s"}
type["ON"] = Abbr:new{formatStr = "Highway %s", exceptions={["QEW"] = "QEW"}}
do -- Nova Scotia
local function processTypeExceptions(exceptions, default, formatArgs)
return function (args)
local formatArguments = {}
for i,v in ipairs(formatArgs) do
formatArguments[i] = args[v]
end
local type = args.type
local formatStr = exceptions[type] or default
args.override = format(formatStr, unpack(formatArguments))
end
end
local typeExceptions = {["Hwy"] = "Hwy %s", ["NS"] = "Hwy %s", ["PTH"] = "Hwy %s", ["Route"] = "Route %s"}
local preprocessor = processTypeExceptions(typeExceptions, '', {"route"})
type["NS"] = Abbr:new{formatStr = "%s", formatArgs = {"override"}, preprocessors = {preprocessor}}
end -- Nova Scotia
end -- Provincial highways
abbrs["TCH"] = Abbr:new{formatStr = "Hwy %s (TCH)"} -- Trans-Canada Highway
do -- Autoroutes
local abbr = Abbr:new{formatStr = "A-%s"}
abbrs["Autoroute"] = abbr
abbrs["A"] = abbr
end -- Autoroutes
abbrs["CR"] = Abbr:new{formatStr = "CR %s"} -- County roads
do -- Secondary Highways
local type = Type:new{["ON"] = Abbr:new{formatStr = "Hwy %s"}}
abbrs["Sec"] = type
abbrs["Secondary"] = type
end -- Secondary Highways
do -- Municipal roads
local function countyCheck(args)
local county = args.county
if county == "Kawartha Lakes" then
args.countyFormatArg = "K.L. "
else
args.countyFormatArg = ""
end
end
abbrs["MR"] = Abbr:new{formatStr = "%sRoad %s", formatArgs = {"countyFormatArg", "route"}, preprocessors = {countyCheck}}
end -- Municipal roads
abbrs["RR"] = Abbr:new{formatStr = "RR %s"} -- Regional roads
abbrs["Trunk"] = Type:new{["NS"] = Abbr:new{formatStr = "Trunk %s"}} -- Trunk highways
abbrs["PR"] = Abbr:new{formatStr = "PR %s"} -- Provincial roads
end
p.abbrs = abbrs
return p