Permanently protected module

Difference between revisions of "Module:Data"

From Yugipedia
Jump to: navigation, search
(Interface to handle Module:Database.)
 
(top: Restoring revision 4406271 by User:Becasita on 2020-01-21 23:34:06. Remove backwards compatibility code.)
(Tag: New user edit)
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
-- <pre>
 
-- <pre>
-- @name Data
+
return require( 'Module:Data/loader' )()
-- @description Interface for Module:Database.
 
-- @notes Internal-only, so far.
 
-- @author [[User:Becasita]]
 
-- @contact [[User talk:Becasita]]
 
 
 
-------------------
 
-- Export variable:
 
-------------------
 
local D = {};
 
 
 
--------------
 
-- Load data:
 
--------------
 
local DATA = mw.loadData( 'Module:Database' );
 
 
 
----------------------
 
-- Internal functions:
 
----------------------
 
-- @name normalize
 
-- @description Normalize de input.
 
local function normalize( arg )
 
return type( arg ) == 'string'
 
and arg:lower()
 
:gsub(    '%-', '' ) -- Remove dashes.
 
:gsub(    ' ', '' ) -- Remove spaces.
 
:gsub( 'north', '' ) -- Remove "north".
 
:gsub( 'rare$', '' ) -- Remove "rare" at the end.
 
or nil
 
;
 
end
 
 
 
-----------
 
-- Methods:
 
-----------
 
-- @name getRg
 
-- @parameter {string} «arg»
 
-- @return {string|nil} Region index.
 
-- @description Gets the region index for «arg». «nil» if not found.
 
function D.getRg( arg )
 
return DATA.rg[ normalize( arg ) ];
 
end
 
 
 
-- @name getRegion
 
-- @parameter {string} «arg»
 
-- @return {string|nil} Region name.
 
-- @description Gets the region name for «arg». «nil» if not found.
 
function D.getRegion( arg )
 
return DATA.region[ D.getRg( arg ) ];
 
end
 
 
 
-- @name getLn
 
-- @parameter {string} «arg»
 
-- @return {string|nil} Language index.
 
-- @description Gets the language index for «arg». «nil» if not found.
 
function D.getLn( arg )
 
return DATA.ln[ D.getRg( arg ) ];
 
end
 
 
 
-- @name getLanguage
 
-- @parameter {string} «arg»
 
-- @return {string|nil} Language name.
 
-- @description Gets the language name for «arg». «nil» if not found.
 
function D.getLanguage( arg )
 
return DATA.language[ D.getLn( arg ) ];
 
end
 
 
 
-- @name getR
 
-- @parameter {string} «arg»
 
-- @return {string|nil} Rarity abbreviation.
 
-- @description Gets the rarity abbreviation for «arg». «nil» if not found.
 
function D.getR( arg )
 
return DATA.r[ normalize( arg ) ];
 
end
 
 
 
-- @name getRarity
 
-- @parameter {string} «arg»
 
-- @return {string|nil} Rarity name.
 
-- @description Gets the rarity name for «arg». «nil» if not found.
 
function D.getRarity( arg )
 
return DATA.rarity[ D.getR( arg ) ];
 
end
 
 
 
----------
 
-- Return:
 
----------
 
return D;
 
 
-- </pre>
 
-- </pre>

Latest revision as of 22:55, 17 March 2023

-- <pre>
return require( 'Module:Data/loader' )()
-- </pre>