Module:RestrictionChecker: Difference between revisions
From Terra Invicta Official Wiki
Created page with "-- Helper Module for checking restrictions local p = {} local CommaSplitModule = require('Module:CommaSplit') local slen = string.len local sfind = string.find local ssub = string.sub ---@param restrictionsTable is a table of restrictions ---@dataRow is the row from the data table to check the restrictions against. ---@return true if all restrictions pass function p.AllPass(restrictionsTable, dataRow) local passesAllRestrictions = true for _, restrictionsRowText in..." |
No edit summary |
||
| Line 15: | Line 15: | ||
local passesAllRestrictions = true | local passesAllRestrictions = true | ||
for _, restrictionsRowText in ipairs(restrictionsTable) do -- Consider each restrictionsTable row one by one: | for _, restrictionsRowText in ipairs(restrictionsTable) do -- Consider each restrictionsTable row one by one: | ||
local restrictionsRow = | local restrictionsRow = CommaSplitModule.CommaSplit(restrictionsRowText) | ||
if restrictionsRow[1] == 'Match' then | if restrictionsRow[1] == 'Match' then | ||
if dataRow[restrictionsRow[2]] ~= restrictionsRow[3] then | if dataRow[restrictionsRow[2]] ~= restrictionsRow[3] then | ||
Revision as of 05:26, 19 January 2026
Documentation for this module may be created at Module:RestrictionChecker/doc
-- Helper Module for checking restrictions
local p = {}
local CommaSplitModule = require('Module:CommaSplit')
local slen = string.len
local sfind = string.find
local ssub = string.sub
---@param restrictionsTable is a table of restrictions
---@dataRow is the row from the data table to check the restrictions against.
---@return true if all restrictions pass
function p.AllPass(restrictionsTable, dataRow)
local passesAllRestrictions = true
for _, restrictionsRowText in ipairs(restrictionsTable) do -- Consider each restrictionsTable row one by one:
local restrictionsRow = CommaSplitModule.CommaSplit(restrictionsRowText)
if restrictionsRow[1] == 'Match' then
if dataRow[restrictionsRow[2]] ~= restrictionsRow[3] then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'Not Match' then
if dataRow[restrictionsRow[2]] == restrictionsRow[3] then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'Contains' then
if not sfind(dataRow[restrictionsRow[2]], restrictionsRow[3], 1, true) then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'In List' then
local inList = false
for i = 0, 100 do
if not dataRow[restrictionsRow[2] .. '/' .. i] or dataRow[restrictionsRow[2] .. '/' .. i] == '' then
break
elseif dataRow[restrictionsRow[2] .. '/' .. i] == restrictionsRow[3] then
inList = true
end
end
if not inList then
passesAllRestrictions = false
end
elseif restrictionsRow[1] == 'Not In List' then
local inList = false
for i = 0, 100 do
if not dataRow[restrictionsRow[2] .. '/' .. i] or dataRow[restrictionsRow[2] .. '/' .. i] == '' then
break
elseif dataRow[restrictionsRow[2] .. '/' .. i] == restrictionsRow[3] then
inList = true
end
end
if inList then
passesAllRestrictions = false
end
end
end
return passesAllRestrictions
end
return p


