Module:Writing systems

From The Languages of David J. Peterson
Revision as of 21:47, 31 March 2019 by Djpwikiadmin (talk | contribs) (Created page with "local export = {} local System = {} function System:getCode() return self._code end function System:getCanonicalName() return self._rawData.canonicalName end function...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local System = {}


function System:getCode()
	return self._code
end


function System:getCanonicalName()
	return self._rawData.canonicalName
end


function System:getOtherNames()
	return self._rawData.otherNames or {}
end


--function System:getAllNames()
--	return self._rawData.names
--end


function System:getType()
	return "Writing system"
end


function System:getCategoryName()
	return self._rawData.category or mw.getContentLanguage():ucfirst(self:getCanonicalName() .. "s")
end

function System:getRawData()
	return self._rawData
end


function System:toJSON()
	local ret = {
		canonicalName = self:getCanonicalName(),
		categoryName = self:getCategoryName(),
		code = self._code,
		otherNames = self:getOtherNames(),
		type = self:getType(),
	}
	
	return require("Module:JSON").toJSON(ret)
end


System.__index = System


function export.makeObject(code, data)
	return data and setmetatable({ _rawData = data, _code = code }, System) or nil
end


function export.getByCode(code)
	return export.makeObject(code, mw.loadData("Module:writing systems/data")[code])
end

return export