Difference between revisions of "Module:Data/static/medium"

From Yugipedia
Jump to: navigation, search
(Medium data manager.)
 
(Remove direct dependency on the region data.)
Line 1: Line 1:
 
-- <pre>
 
-- <pre>
-- TODO: find better way using region endpoint.
 
 
local thisData = mw.loadData( 'Module:Data/static/medium/data' )
 
local thisData = mw.loadData( 'Module:Data/static/medium/data' )
  
local regionData = mw.loadData( 'Module:Data/static/region/data' )
+
local DATA = require( 'Module:Data/sandbox' )
  
 
local function normalize( v )
 
local function normalize( v )
Line 10: Line 9:
 
:lower()
 
:lower()
 
:gsub( "[%s%-_'!]", '' )
 
:gsub( "[%s%-_'!]", '' )
:gsub(    'north', '' )
 
 
:gsub(    'yugioh', '' )
 
:gsub(    'yugioh', '' )
 
:gsub(  'cardgame', '' )
 
:gsub(  'cardgame', '' )
Line 17: Line 15:
  
 
return function( v )
 
return function( v )
local normalizedV = normalize( v )
 
 
 
return thisData.main[
 
return thisData.main[
 
thisData.normalize[
 
thisData.normalize[
regionData.normalize[
+
( DATA.getRegion( v ) or {} ).index
normalizedV
+
or normalize( v )
] or normalizedV
 
 
]
 
]
 
]
 
]
 
end
 
end
 
-- </pre>
 
-- </pre>

Revision as of 13:41, 27 December 2019

-- <pre>
local thisData = mw.loadData( 'Module:Data/static/medium/data' )

local DATA = require( 'Module:Data/sandbox' )

local function normalize( v )
	return type( v ) == 'string'
		and mw.text.trim( v )
			:lower()
			:gsub( "[%s%-_'!]", '' )
			:gsub(    'yugioh', '' )
			:gsub(  'cardgame', '' )
		or nil
end

return function( v )
	return thisData.main[
		thisData.normalize[
			( DATA.getRegion( v ) or {} ).index
			or normalize( v )
		]
	]
end
-- </pre>