Module:NPVIC status
Accepts raw status strings from the article National Popular Vote Interstate Compact and returns processed status information for use in that article.
The first parameter takes either 1) a list of US states by postal abbreviation, or 2) the word "passed" or "pending", which is interpreted as the name of a labelled section of the invoking page which contains such a list. The module then passes this list to the specified function.
Functions
"States" returns the number of states (excluding DC) listed in the input string. An unnamed argument with value "spell" will cause the number to be spelled out per MOS:NUMERAL.
{{#invoke:NPVIC status|states|section}}
"EVs" returns the total number of electoral votes controlled by jurisdictions listed in the input string.
{{#invoke:NPVIC status|EVs|section}}
"Overlays" returns overlay maps indicating the compact has a status of "passed" (green) or "pending" (yellow), in the jurisdictions listed in the input string. This function takes an additional "size" argument to ensure that the overlay images align with the base map.
{{#invoke:NPVIC status|overlays|section|size=size}}
"Percent" divides the value returned by EVs by a denominator given as the second argument, or if no denominator is given, by 538, and returns the resulting value as a percentage. The third parameter may be used to specify the number of decimal places to include; by default, one is included.
{{#invoke:NPVIC status|percent|section|270|0}}
"Signatories" returns a bulleted list of the jurisdictions where the compact has passed into law. The "passed" section is used automatically.
{{#invoke:NPVIC status|signatories}}
local p = {}
function p.states(frame)
local states = frame:expandTemplate{ title = 'section transclude', args = { frame.args['section'] } }
local total = 0
for state in mw.ustring.gmatch( states, "%a%a" ) do
if state~='DC' then
total = total + 1
end
end
return total
end
function p.EVs(frame)
local states = frame:expandTemplate{ title = 'section transclude', args = { frame.args['section'] } }
if states == '' then
states = frame.args[1]
end
if states == '' then
return frame:expandTemplate{ title = 'error', args = { 'This total relies on data stored elsewhere on this page, which is not available when editing this section in isolation.' } }
end
local total = 0
for state in mw.ustring.gmatch( states, "%a%a" ) do
seats = frame:expandTemplate{ title = 'USHRseats', args = { state } }
if type(tonumber(seats))=='nil' then
total = error("Unrecognized state")
break
else
total = total + seats + 2
end
end
return total
end
function p.overlays(frame)
local states = frame:expandTemplate{ title = 'section transclude', args = { frame.args['section'] } }
local size = frame.args['size'] or '325px'
if frame.args['section']=='passed' then
color = 'green'
elseif frame.args['section']=='pending' then
color = 'yellow'
end
local overlays = ''
for state in mw.ustring.gmatch( states, "%a%a" ) do
state_overlay = '<div style=\"position: absolute; left: 0px; top: 0px\">[[File:' .. state .. ' ' .. color .. '.svg|' .. size .. ']]</div>'
overlays = overlays .. state_overlay
end
return overlays
end
function p.signatories(frame)
local states = frame:expandTemplate{ title = 'section transclude', args = { 'passed' } }
local signatories = ''
for state in mw.ustring.gmatch( states, "%a%a" ) do
state_name = frame:expandTemplate{ title = 'US State Abbrev', args = { state } }
local dab = ''
if state_name=='New York' or state_name=='Washington' then
dab=' (state)'
end
signatories = signatories .. '\n* ' .. frame:expandTemplate{ title = 'flagicon', args = { state_name } } .. ' [[' .. state_name .. dab .. '|' .. state_name .. ']]'
end
return signatories
end
return p