Modul:Data/DE-096775621/1/4

aus Wikipedia, der freien Enzyklopädie
local p = {}
local tData = {
	["rootfield"] = {
		["access date"] = "2017-02-20",
		["Einwohnerzahlen date"] = "1984-01-01",
		["page"] = "http://www.vgem-marktheidenfeld.de/verwalt/EWzahlen.htm",
		["publisher"] = "Verwaltungsgemeinschaft Marktheidenfeld",
		["title"] = "Entwicklung der Einwohnerzahlen seit 1981",
		["url"] = "http://www.vgem-marktheidenfeld.de/verwalt/EWzahlen.htm",
	},
	["value"] = {
		["Birkenfeld"]=1498,
		["Billingshausen"]=414,
		["Gemeinde Birkenfeld"]=1912,
		["Bischbrunn"]=958,
		["Oberndorf"]=830,
		["Gemeinde Bischbrunn"]=1788,
		["Erlenbach"]=1521,
		["Tiefenthal"]=527,
		["Gemeinde Erlenbach"]=2048,
		["Esselbach"]=919,
		["Kredenbach"]=447,
		["Steinmark"]=390,
		["Gemeinde Esselbach"]=1756,
		["Hafenlohr"]=1327,
		["Windheim"]=414,
		["Gemeinde Hafenlohr"]=1741,
		["Karbach"]=1304,
		["Roden"]=501,
		["Ansbach"]=411,
		["Gemeinde Roden"]=912,
		["Rothenfels"]=490,
		["Bergrothenfels"]=578,
		["Stadt Rothenfels"]=1068,
		["Urspringen"]=1159,
		["VG"]=13688,
	},
	["valuefield"] = {
		[""] = 1,
		["Einwohnerzahlen"] = 1,
	},
}

function p.getData(tArgs)
	if type(tArgs) == type({}) then
		local sArgs ="\n* fieldError\n* keyError\n* arg1"
		local tClip = {tData["value"][tArgs.key]}
		if tArgs.tryOther and not tClip then
			local b, tSub = pcall(require, "Module:Data/DE-096775621/1/3")
			if type(tSub) == type({}) and tSub.getData then
				return tSub.getData(tArgs)
			end
		end
		tArgs.field = tArgs.field or ""
		if tData["rootfield"][tArgs.field] then
			return tData["rootfield"][tArgs.field]
		elseif tArgs.field == "field list" then
			local s = "* field list\n*key table" .. sArgs
			local t = {}
			for i, v in pairs(tData["rootfield"]) do
				t[#t + 1] = i
			end
			table.sort(t)
			for i, v in pairs(t) do
				s = s .. "\n* " .. v
			end
			t = {}
			for i, v in pairs(tData["valuefield"]) do
				t[#t + 1] = i
			end
			table.sort(t)
			for i, v in pairs(t) do
				s = s .. "\n* " .. v
			end
			return s
		elseif tArgs.field == "key table" then
			local s = '{| class="wikitable"\n!key\n'
			local t = {}
			for i, v in pairs(tData["value"]) do
				t[#t + 1] = {i}
			end
			table.sort(t, function(t1 ,t2) return t1[1] < t2[1] end)
			for i, v in pairs(t) do
				s = s .. "|-\n|" .. v[1] .. "\n"
			end
			return s .. "|}"
		elseif (sArgs .. "\n"):find("\n* " .. tArgs.field .. "\n", 1 ,true) then
			return tArgs[tArgs.field]
		elseif not tClip then
			tArgs.keyError = tArgs.keyError or '<span class="error">key = ""</span>'
			return tArgs.keyError
		elseif tData["valuefield"][tArgs.field] then
			return tClip[tData["valuefield"][tArgs.field]]
		else
			tArgs.fieldError = tArgs.fieldError or '<span class="error">field = "field list"</span>'
			return tArgs.fieldError
		end
	else
		return '<span class="error">tArgs = {}</span>'
	end
end

function p.invokeData(frame)
	local t = {}
	t.key = frame.args[1] or frame.args["key"]
	t.field = frame.args[2] or frame.args["field"]
	for i, v in pairs(frame.args) do
		t[i] = t[i] or v
	end
	return p.getData(t)
end

return p