blob: c0ee862626036052e3bf6cf1211b5208e0a81185 (
plain) (
blame)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
module Arel
module Predicates
class Binary < Predicate
def eval(row)
operand1.eval(row).send(operator, operand2.eval(row))
end
end
class Unary < Predicate
def eval(row)
operand.eval(row).send(operator)
end
end
class Not < Unary
def operator; '!' end
end
class CompoundPredicate < Binary
def eval(row)
eval "operand1.eval(row) #{operator} operand2.eval(row)"
end
end
class Or < CompoundPredicate
def operator; :or end
end
class And < CompoundPredicate
def operator; :and end
end
class GroupedPredicate < Polyadic
def eval(row)
group = additional_operands.inject([]) do |results, operand|
results << operator.new(operand1, operand)
end
group.send(compounder) do |operation|
operation.eval(row)
end
end
end
class Any < GroupedPredicate
def compounder; :any? end
end
class All < GroupedPredicate
def compounder; :all? end
end
class Equality < Binary
def operator; :== end
end
class Inequality < Equality
def eval(row)
operand1.eval(row) != operand2.eval(row)
end
end
class GreaterThanOrEqualTo < Binary
def operator; :>= end
end
class GreaterThan < Binary
def operator; :> end
end
class LessThanOrEqualTo < Binary
def operator; :<= end
end
class LessThan < Binary
def operator; :< end
end
class Match < Binary
def operator; :=~ end
end
class NotMatch < Binary
def eval(row)
operand1.eval(row) !~ operand2.eval(row)
end
end
class In < Binary
def eval(row)
operand2.eval(row).include?(operand1.eval(row))
end
end
class NotIn < Binary
def eval(row)
!(operand2.eval(row).include?(operand1.eval(row)))
end
end
end
end
|