Jump to content

Module:ATC code to template name: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
move data to submodule, simplify coding
more efficient?
Line 1: Line 1:
-- this module provides a lookup from ATC codes to their associated navbox templates --
-- this module provides a lookup from ATC codes to their associated navbox templates --
local data = require("Module:ATC code to template name/data")
local data = mw.loadData("Module:ATC code to template name/data")
local lookuptable = data.lookuptable
local lookuptable = data.lookuptable
p = {}
p = {}

Revision as of 04:40, 2 June 2021

-- this module provides a lookup from ATC codes to their associated navbox templates --
local data = mw.loadData("Module:ATC code to template name/data")
local lookuptable = data.lookuptable
p = {}

function p.translate(frame)
	local input = frame.args[1]
	for k,v in pairs(lookuptable) do
		if v.code == input then
			p.nameoftemplate = v.template
			if ( p.nameoftemplate == 42 ) then
				p.out = 1
				error("ATC code not specific enough - please use one further character (example: instead of M01, use M01A)")
				end
			if ( p.nameoftemplate == tostring(42) ) then
				p.out = 1
				error("ATC code not specific enough - please use one further character (example: instead of M01, use M01A)")
				end
			if ( p.nameoftemplate ~= nil ) then
				p.out = frame:expandTemplate{ title = p.nameoftemplate }
				end
			end
    	end
    if p.out == nil then
        error("Invalid ATC code (or the ATC code does not have a template matched to it)")
    end
    if ( p.out ~= 1 ) then
    	return p.out
	end
end

return p