-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathComparisonOperatorHelper.lua
More file actions
85 lines (72 loc) · 2.09 KB
/
ComparisonOperatorHelper.lua
File metadata and controls
85 lines (72 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local utils = require("Utils")
local model = {
evaluate = function(opt, isNegative, isIgnoreCase, value, valueToCompare, valuesToCompare)
-- Private functions
local function contains(_value, _valueToCompare, _isNegative, _isIgnoreCase)
if (_valueToCompare == "*" and (not utils.isNilOrEmpty(_value))) then
return true
end
if (_isIgnoreCase) then
_value = string.upper(_value)
_valueToCompare = string.upper(_valueToCompare)
end
local evaluation = utils:contains(_value, _valueToCompare)
if (_isNegative) then
return not evaluation
else
return evaluation
end
end
local function equals(_value, _valueToCompare, _isNegative, _isIgnoreCase)
if (_isIgnoreCase) then
_value = string.upper(_value)
_valueToCompare = string.upper(_valueToCompare)
end
local evaluation = _value == _valueToCompare
if (_isNegative) then
return not evaluation
else
return evaluation
end
end
local function equalsAny(_value, _valuesToCompare, _isNegative, _isIgnoreCase)
for _, vToCompare in pairs(_valuesToCompare) do
if(equals(_value, vToCompare, false, _isIgnoreCase)) then
return not _isNegative
end
end
return _isNegative
end
local function containsAny(_value, _valuesToCompare, _isNegative, _isIgnoreCase)
for _, vToCompare in pairs(_valuesToCompare) do
if(contains(_value, vToCompare, false, _isIgnoreCase)) then
return not _isNegative
end
end
return _isNegative
end
if (value == nil) then
value = ""
end
if (valueToCompare == nil) then
valueToCompare = ""
end
if (utils.isTable(valuesToCompare) == false) then
valuesToCompare = {}
end
if (opt == "Equals") then
return equals(value, valueToCompare, isNegative, isIgnoreCase)
end
if (opt == "Contains") then
return contains(value, valueToCompare, isNegative, isIgnoreCase)
end
if (opt == "EqualsAny") then
return equalsAny(value, valuesToCompare, isNegative, isIgnoreCase)
end
if (opt == "ContainsAny") then
return containsAny(value, valuesToCompare, isNegative, isIgnoreCase)
end
return false
end
}
return model