predicator 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d52e8264560ab508f15b4580664b339b16a021b7
4
- data.tar.gz: ba88b351e379ee8432417467176f24f95ae86101
3
+ metadata.gz: b6f75523bd14777d85c7d52472823bad7eafa31f
4
+ data.tar.gz: cbf63f511abaccbac93ed564256d5d0caea7da87
5
5
  SHA512:
6
- metadata.gz: 4064737f39e41018800fe9b93f8d49c7ae03ae33cb240bdba0a33ccbe57b190d67e335c773deb15069988d98dbfab0e98a4f75c8b657cacabca2d045491195b1
7
- data.tar.gz: b6846e08b25fdb5e2ebf3668c20cb5faa84a452200050fe52798f47843df8b1a1e2a0d826be66cb80fc6cac0776c7283f0db839a05796678d6c010bdce2b2835
6
+ metadata.gz: 7c0c9e0fa3737b4c6f1ec27a20254197fbe0a52825f37cb2978c02c829473d3fd3777f5e5937cb08c754783acc0c1a9188f8e31054a4ab4eb1dfab325873c68a
7
+ data.tar.gz: af32c18e7d32ccf7047f02d7bafaa71fbb7d3fa0b7383d47f78854440fdb1ef45884d832f37e1ff364ca19a5ff90783fe6715b4e33c9b7e247ff6cb169a80444
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ ### 0.3.0 / 2016-03-11
2
+
3
+ * Adds more relation predicates (GT, LT, GTE, LTE, NEQ)
4
+ * Adds between predicate
5
+
1
6
  ### 0.2.1 / 2016-02-22
2
7
 
3
8
  * Makes RACC a development dependency (trying to get working on MagLev)
@@ -2,17 +2,16 @@ require "ostruct"
2
2
 
3
3
  module Predicator
4
4
  class Context
5
- attr_reader :entities
5
+ attr_reader :bindings
6
6
 
7
7
  def initialize
8
- @entities = {}
8
+ @bindings = {}
9
9
  end
10
10
 
11
11
  def bind name, value
12
12
  value = OpenStruct.new(value) if value.kind_of? Hash
13
- entities[name.to_s] = value
13
+ bindings[name.to_s] = value
14
14
  end
15
- alias :[]= :bind
16
15
 
17
16
  def value_for input
18
17
  return input unless input.kind_of? Predicator::Variable
@@ -10,76 +10,92 @@ module Predicator
10
10
  ##### State transition tables begin ###
11
11
 
12
12
  racc_action_table = [
13
- 9, 26, 25, 7, 8, 14, 15, 16, 17, 18,
14
- 9, 23, 5, 7, 8, 14, 15, 16, 17, 18,
15
- 9, 31, 5, 7, 8, 14, 15, 16, 17, 18,
16
- 9, nil, 5, 7, 8, 14, 15, 16, 17, 18,
17
- 20, 21, 5, 14, 15, 16, 17, 18, nil, nil,
18
- 9, nil, 29, 7, 8, 14, 15, 16, 17, 18,
19
- 19, nil, 5, 20, 21 ]
13
+ 9, 31, 32, 7, 8, 14, 15, 16, 17, 18,
14
+ 9, 43, 6, 7, 8, 14, 15, 16, 17, 18,
15
+ 9, 44, 6, 7, 8, 14, 15, 16, 17, 18,
16
+ 9, nil, 6, 7, 8, 14, 15, 16, 17, 18,
17
+ 9, nil, 6, 7, 8, 14, 15, 16, 17, 18,
18
+ 20, 21, 6, 19, nil, nil, 20, 21, nil, 22,
19
+ nil, nil, 42, 23, 28, 27, 26, 25, 24, 14,
20
+ 15, 16, 17, 18, 14, 15, 16, 17, 18, 14,
21
+ 15, 16, 17, 18, 14, 15, 16, 17, 18, 14,
22
+ 15, 16, 17, 18, 14, 15, 16, 17, 18, 14,
23
+ 15, 16, 17, 18, 14, 15, 16, 17, 18 ]
20
24
 
21
25
  racc_action_check = [
22
- 0, 19, 18, 0, 0, 0, 0, 0, 0, 0,
23
- 20, 6, 0, 20, 20, 20, 20, 20, 20, 20,
24
- 5, 25, 20, 5, 5, 5, 5, 5, 5, 5,
25
- 21, nil, 5, 21, 21, 21, 21, 21, 21, 21,
26
- 22, 22, 21, 23, 23, 23, 23, 23, nil, nil,
27
- 9, nil, 22, 9, 9, 9, 9, 9, 9, 9,
28
- 1, nil, 9, 1, 1 ]
26
+ 0, 18, 19, 0, 0, 0, 0, 0, 0, 0,
27
+ 6, 31, 0, 6, 6, 6, 6, 6, 6, 6,
28
+ 9, 35, 6, 9, 9, 9, 9, 9, 9, 9,
29
+ 20, nil, 9, 20, 20, 20, 20, 20, 20, 20,
30
+ 21, nil, 20, 21, 21, 21, 21, 21, 21, 21,
31
+ 29, 29, 21, 1, nil, nil, 1, 1, nil, 5,
32
+ nil, nil, 29, 5, 5, 5, 5, 5, 5, 22,
33
+ 22, 22, 22, 22, 23, 23, 23, 23, 23, 24,
34
+ 24, 24, 24, 24, 25, 25, 25, 25, 25, 26,
35
+ 26, 26, 26, 26, 27, 27, 27, 27, 27, 28,
36
+ 28, 28, 28, 28, 44, 44, 44, 44, 44 ]
29
37
 
30
38
  racc_action_pointer = [
31
- -2, 60, nil, nil, nil, 18, -2, nil, nil, 48,
32
- nil, nil, nil, nil, nil, nil, nil, nil, -10, 1,
33
- 8, 28, 37, 36, nil, 10, nil, nil, nil, nil,
34
- nil, nil ]
39
+ -2, 53, nil, nil, nil, 47, 8, nil, nil, 18,
40
+ nil, nil, nil, nil, nil, nil, nil, nil, -12, 2,
41
+ 28, 38, 62, 67, 72, 77, 82, 87, 92, 47,
42
+ nil, 0, nil, nil, nil, 18, nil, nil, nil, nil,
43
+ nil, nil, nil, nil, 97, nil ]
35
44
 
36
45
  racc_action_default = [
37
- -20, -20, -1, -2, -3, -20, -20, -6, -7, -20,
38
- -11, -12, -13, -14, -15, -16, -17, -18, -20, -20,
39
- -20, -20, -20, -20, -10, -20, 32, -8, -9, -4,
40
- -5, -19 ]
46
+ -26, -26, -1, -2, -3, -26, -26, -12, -13, -26,
47
+ -17, -18, -19, -20, -21, -22, -23, -24, -26, -26,
48
+ -26, -26, -26, -26, -26, -26, -26, -26, -26, -26,
49
+ -16, -26, 46, -14, -15, -26, -6, -7, -8, -9,
50
+ -10, -11, -5, -25, -26, -4 ]
41
51
 
42
52
  racc_goto_table = [
43
- 1, 30, nil, nil, nil, 22, nil, nil, nil, 24,
44
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
45
- 27, 28 ]
53
+ 35, 36, 37, 38, 39, 40, 41, 1, nil, nil,
54
+ nil, nil, nil, 29, nil, nil, 30, nil, nil, nil,
55
+ nil, nil, 45, nil, nil, nil, nil, 33, 34 ]
46
56
 
47
57
  racc_goto_check = [
48
- 1, 5, nil, nil, nil, 1, nil, nil, nil, 1,
49
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
50
- 1, 1 ]
58
+ 5, 5, 5, 5, 5, 5, 5, 1, nil, nil,
59
+ nil, nil, nil, 1, nil, nil, 1, nil, nil, nil,
60
+ nil, nil, 5, nil, nil, nil, nil, 1, 1 ]
51
61
 
52
62
  racc_goto_pointer = [
53
- nil, 0, nil, nil, nil, -22, nil, nil, nil, nil ]
63
+ nil, 7, nil, nil, nil, -22, nil, nil, nil, nil ]
54
64
 
55
65
  racc_goto_default = [
56
- nil, nil, 2, 3, 4, 6, 10, 11, 12, 13 ]
66
+ nil, nil, 2, 3, 4, 5, 10, 11, 12, 13 ]
57
67
 
58
68
  racc_reduce_table = [
59
69
  0, 0, :racc_error,
60
- 1, 17, :_reduce_none,
61
- 1, 17, :_reduce_none,
62
- 1, 17, :_reduce_none,
63
- 3, 17, :_reduce_none,
64
- 3, 18, :_reduce_5,
65
- 1, 19, :_reduce_6,
66
- 1, 19, :_reduce_7,
67
- 3, 20, :_reduce_8,
68
- 3, 20, :_reduce_9,
69
- 2, 20, :_reduce_10,
70
- 1, 21, :_reduce_none,
71
- 1, 21, :_reduce_none,
72
- 1, 22, :_reduce_none,
73
- 1, 22, :_reduce_none,
74
- 1, 24, :_reduce_15,
75
- 1, 25, :_reduce_16,
76
- 1, 25, :_reduce_17,
77
- 1, 25, :_reduce_18,
78
- 3, 23, :_reduce_19 ]
79
-
80
- racc_reduce_n = 20
81
-
82
- racc_shift_n = 32
70
+ 1, 23, :_reduce_none,
71
+ 1, 23, :_reduce_none,
72
+ 1, 23, :_reduce_none,
73
+ 5, 23, :_reduce_4,
74
+ 3, 23, :_reduce_none,
75
+ 3, 24, :_reduce_6,
76
+ 3, 24, :_reduce_7,
77
+ 3, 24, :_reduce_8,
78
+ 3, 24, :_reduce_9,
79
+ 3, 24, :_reduce_10,
80
+ 3, 24, :_reduce_11,
81
+ 1, 25, :_reduce_12,
82
+ 1, 25, :_reduce_13,
83
+ 3, 26, :_reduce_14,
84
+ 3, 26, :_reduce_15,
85
+ 2, 26, :_reduce_16,
86
+ 1, 27, :_reduce_none,
87
+ 1, 27, :_reduce_none,
88
+ 1, 28, :_reduce_none,
89
+ 1, 28, :_reduce_none,
90
+ 1, 30, :_reduce_21,
91
+ 1, 31, :_reduce_22,
92
+ 1, 31, :_reduce_23,
93
+ 1, 31, :_reduce_24,
94
+ 3, 29, :_reduce_25 ]
95
+
96
+ racc_reduce_n = 26
97
+
98
+ racc_shift_n = 46
83
99
 
84
100
  racc_token_table = {
85
101
  false => 0,
@@ -94,12 +110,18 @@ racc_token_table = {
94
110
  :tINTEGER => 9,
95
111
  :tDATE => 10,
96
112
  :tIDENTIFIER => 11,
97
- :tDOT => 12,
98
- :tEQUAL => 13,
113
+ :tBETWEEN => 12,
114
+ :tDOT => 13,
99
115
  :tLPAREN => 14,
100
- :tRPAREN => 15 }
116
+ :tRPAREN => 15,
117
+ :tEQ => 16,
118
+ :tNEQ => 17,
119
+ :tLEQ => 18,
120
+ :tGEQ => 19,
121
+ :tLT => 20,
122
+ :tGT => 21 }
101
123
 
102
- racc_nt_base = 16
124
+ racc_nt_base = 22
103
125
 
104
126
  racc_use_result_var = false
105
127
 
@@ -132,13 +154,19 @@ Racc_token_to_s_table = [
132
154
  "tINTEGER",
133
155
  "tDATE",
134
156
  "tIDENTIFIER",
157
+ "tBETWEEN",
135
158
  "tDOT",
136
- "tEQUAL",
137
159
  "tLPAREN",
138
160
  "tRPAREN",
161
+ "tEQ",
162
+ "tNEQ",
163
+ "tLEQ",
164
+ "tGEQ",
165
+ "tLT",
166
+ "tGT",
139
167
  "$start",
140
168
  "predicate",
141
- "equals_predicate",
169
+ "relation_predicate",
142
170
  "boolean_predicate",
143
171
  "logical_predicate",
144
172
  "value",
@@ -159,78 +187,114 @@ Racc_debug_parser = false
159
187
 
160
188
  # reduce 3 omitted
161
189
 
162
- # reduce 4 omitted
190
+ module_eval(<<'.,.,', 'parser.y', 13)
191
+ def _reduce_4(val, _values)
192
+ Predicator::Predicates::Between.new val[0], val[2], val[4]
193
+ end
194
+ .,.,
195
+
196
+ # reduce 5 omitted
163
197
 
164
- module_eval(<<'.,.,', 'parser.y', 16)
165
- def _reduce_5(val, _values)
166
- Predicator::Predicates::Equals.new val[0], val[2]
198
+ module_eval(<<'.,.,', 'parser.y', 17)
199
+ def _reduce_6(val, _values)
200
+ Predicator::Predicates::Equal.new val[0], val[2]
201
+ end
202
+ .,.,
203
+
204
+ module_eval(<<'.,.,', 'parser.y', 18)
205
+ def _reduce_7(val, _values)
206
+ Predicator::Predicates::GreaterThan.new val[0], val[2]
167
207
  end
168
208
  .,.,
169
209
 
170
210
  module_eval(<<'.,.,', 'parser.y', 19)
171
- def _reduce_6(val, _values)
172
- Predicator::Predicates::True.new
211
+ def _reduce_8(val, _values)
212
+ Predicator::Predicates::LessThan.new val[0], val[2]
173
213
  end
174
214
  .,.,
175
215
 
176
216
  module_eval(<<'.,.,', 'parser.y', 20)
177
- def _reduce_7(val, _values)
217
+ def _reduce_9(val, _values)
218
+ Predicator::Predicates::GreaterThanOrEqual.new val[0], val[2]
219
+ end
220
+ .,.,
221
+
222
+ module_eval(<<'.,.,', 'parser.y', 21)
223
+ def _reduce_10(val, _values)
224
+ Predicator::Predicates::LessThanOrEqual.new val[0], val[2]
225
+ end
226
+ .,.,
227
+
228
+ module_eval(<<'.,.,', 'parser.y', 22)
229
+ def _reduce_11(val, _values)
230
+ Predicator::Predicates::NotEqual.new val[0], val[2]
231
+ end
232
+ .,.,
233
+
234
+ module_eval(<<'.,.,', 'parser.y', 25)
235
+ def _reduce_12(val, _values)
236
+ Predicator::Predicates::True.new
237
+ end
238
+ .,.,
239
+
240
+ module_eval(<<'.,.,', 'parser.y', 26)
241
+ def _reduce_13(val, _values)
178
242
  Predicator::Predicates::False.new
179
243
  end
180
244
  .,.,
181
245
 
182
- module_eval(<<'.,.,', 'parser.y', 23)
183
- def _reduce_8(val, _values)
246
+ module_eval(<<'.,.,', 'parser.y', 29)
247
+ def _reduce_14(val, _values)
184
248
  Predicator::Predicates::And.new [val[0], val[2]]
185
249
  end
186
250
  .,.,
187
251
 
188
- module_eval(<<'.,.,', 'parser.y', 24)
189
- def _reduce_9(val, _values)
252
+ module_eval(<<'.,.,', 'parser.y', 30)
253
+ def _reduce_15(val, _values)
190
254
  Predicator::Predicates::Or.new [val[0], val[2]]
191
255
  end
192
256
  .,.,
193
257
 
194
- module_eval(<<'.,.,', 'parser.y', 25)
195
- def _reduce_10(val, _values)
258
+ module_eval(<<'.,.,', 'parser.y', 31)
259
+ def _reduce_16(val, _values)
196
260
  Predicator::Predicates::Not.new val[0]
197
261
  end
198
262
  .,.,
199
263
 
200
- # reduce 11 omitted
264
+ # reduce 17 omitted
201
265
 
202
- # reduce 12 omitted
266
+ # reduce 18 omitted
203
267
 
204
- # reduce 13 omitted
268
+ # reduce 19 omitted
205
269
 
206
- # reduce 14 omitted
270
+ # reduce 20 omitted
207
271
 
208
- module_eval(<<'.,.,', 'parser.y', 36)
209
- def _reduce_15(val, _values)
272
+ module_eval(<<'.,.,', 'parser.y', 42)
273
+ def _reduce_21(val, _values)
210
274
  val[0]
211
275
  end
212
276
  .,.,
213
277
 
214
- module_eval(<<'.,.,', 'parser.y', 39)
215
- def _reduce_16(val, _values)
278
+ module_eval(<<'.,.,', 'parser.y', 45)
279
+ def _reduce_22(val, _values)
216
280
  val[0].to_f
217
281
  end
218
282
  .,.,
219
283
 
220
- module_eval(<<'.,.,', 'parser.y', 40)
221
- def _reduce_17(val, _values)
284
+ module_eval(<<'.,.,', 'parser.y', 46)
285
+ def _reduce_23(val, _values)
222
286
  val[0].to_i
223
287
  end
224
288
  .,.,
225
289
 
226
- module_eval(<<'.,.,', 'parser.y', 41)
227
- def _reduce_18(val, _values)
290
+ module_eval(<<'.,.,', 'parser.y', 47)
291
+ def _reduce_24(val, _values)
228
292
  Date.new *val[0]
229
293
  end
230
294
  .,.,
231
295
 
232
- module_eval(<<'.,.,', 'parser.y', 44)
233
- def _reduce_19(val, _values)
296
+ module_eval(<<'.,.,', 'parser.y', 50)
297
+ def _reduce_25(val, _values)
234
298
  Predicator::Variable.new val[0], val[2]
235
299
  end
236
300
  .,.,
@@ -5,10 +5,15 @@ module Predicator
5
5
  class Lexer
6
6
  SPACE = /[ \t\r\n]/
7
7
  DOT = /\./
8
- BANG = /!/
9
- EQUAL = /=/
10
8
  LPAREN = /\(/
11
9
  RPAREN = /\)/
10
+ NEQ = /!=/
11
+ GEQ = />=/
12
+ LEQ = /<=/
13
+ GT = />/
14
+ LT = /</
15
+ EQ = /=/
16
+ BANG = /!/
12
17
  DATE = /(\d{4})-(\d{2})-(\d{2})/i
13
18
  FLOAT = /[+-]?(?:[0-9_]+\.[0-9_]*|\.[0-9_]+|\d+(?=[eE]))(?:[eE][+-]?[0-9_]+)?\b/
14
19
  INTEGER = /[+-]?\d(_?\d)*\b/
@@ -16,6 +21,7 @@ module Predicator
16
21
  FALSE = /false\b/
17
22
  AND = /and/i
18
23
  OR = /or/i
24
+ BETWEEN = /between/i
19
25
  STRING = /(["])(?:\\?.)*?\1/
20
26
  IDENTIFIER = /[a-z][A-Za-z0-9_]*/
21
27
 
@@ -42,18 +48,33 @@ module Predicator
42
48
  when text = @ss.scan(DOT)
43
49
  @tokens.push [:tDOT, text]
44
50
 
45
- when text = @ss.scan(BANG)
46
- @tokens.push [:tBANG, text]
47
-
48
- when text = @ss.scan(EQUAL)
49
- @tokens.push [:tEQUAL, text]
50
-
51
51
  when text = @ss.scan(LPAREN)
52
52
  @tokens.push [:tLPAREN, text]
53
53
 
54
54
  when text = @ss.scan(RPAREN)
55
55
  @tokens.push [:tRPAREN, text]
56
56
 
57
+ when text = @ss.scan(NEQ)
58
+ @tokens.push [:tNEQ, text]
59
+
60
+ when text = @ss.scan(GEQ)
61
+ @tokens.push [:tGEQ, text]
62
+
63
+ when text = @ss.scan(LEQ)
64
+ @tokens.push [:tLEQ, text]
65
+
66
+ when text = @ss.scan(GT)
67
+ @tokens.push [:tGT, text]
68
+
69
+ when text = @ss.scan(LT)
70
+ @tokens.push [:tLT, text]
71
+
72
+ when text = @ss.scan(EQ)
73
+ @tokens.push [:tEQ, text]
74
+
75
+ when text = @ss.scan(BANG)
76
+ @tokens.push [:tBANG, text]
77
+
57
78
  when text = @ss.scan(DATE)
58
79
  args = [ @ss[1], @ss[2], @ss[3] ].map(&:to_i)
59
80
  @tokens.push [:tDATE, args]
@@ -76,6 +97,9 @@ module Predicator
76
97
  when text = @ss.scan(OR)
77
98
  @tokens.push [:tOR, text]
78
99
 
100
+ when text = @ss.scan(BETWEEN)
101
+ @tokens.push [:tBETWEEN, text]
102
+
79
103
  when text = @ss.scan(STRING)
80
104
  @tokens.push [:tSTRING, text[1..-2]]
81
105
 
@@ -4,7 +4,14 @@ require "predicator/generated_parser"
4
4
  require "predicator/lexer"
5
5
  require "predicator/variable"
6
6
 
7
- require "predicator/predicates/equals"
7
+ require "predicator/predicates/relation"
8
+ require "predicator/predicates/equal"
9
+ require "predicator/predicates/not_equal"
10
+ require "predicator/predicates/greater_than"
11
+ require "predicator/predicates/less_than"
12
+ require "predicator/predicates/greater_than_or_equal"
13
+ require "predicator/predicates/less_than_or_equal"
14
+ require "predicator/predicates/between"
8
15
  require "predicator/predicates/true"
9
16
  require "predicator/predicates/false"
10
17
  require "predicator/predicates/and"
@@ -4,26 +4,32 @@ prechigh
4
4
  right tBANG
5
5
  left tAND tOR
6
6
  preclow
7
- token tTRUE tFALSE tSTRING tFLOAT tINTEGER tDATE tIDENTIFIER tDOT tEQUAL
8
- tLPAREN tRPAREN tAND tOR tBANG
7
+ token tTRUE tFALSE tSTRING tFLOAT tINTEGER tDATE tIDENTIFIER tAND tOR tBETWEEN
8
+ tDOT tLPAREN tRPAREN tBANG tEQ tNEQ tLEQ tGEQ tLT tGT
9
9
  rule
10
10
  predicate
11
- : equals_predicate
11
+ : relation_predicate
12
12
  | boolean_predicate
13
13
  | logical_predicate
14
+ | value tBETWEEN value tAND value { Predicator::Predicates::Between.new val[0], val[2], val[4] }
14
15
  | tLPAREN predicate tRPAREN
15
16
  ;
16
- equals_predicate
17
- : value tEQUAL value { Predicator::Predicates::Equals.new val[0], val[2] }
17
+ relation_predicate
18
+ : value tEQ value { Predicator::Predicates::Equal.new val[0], val[2] }
19
+ | value tGT value { Predicator::Predicates::GreaterThan.new val[0], val[2] }
20
+ | value tLT value { Predicator::Predicates::LessThan.new val[0], val[2] }
21
+ | value tGEQ value { Predicator::Predicates::GreaterThanOrEqual.new val[0], val[2] }
22
+ | value tLEQ value { Predicator::Predicates::LessThanOrEqual.new val[0], val[2] }
23
+ | value tNEQ value { Predicator::Predicates::NotEqual.new val[0], val[2] }
18
24
  ;
19
25
  boolean_predicate
20
- : tTRUE { Predicator::Predicates::True.new }
21
- | tFALSE { Predicator::Predicates::False.new }
26
+ : tTRUE { Predicator::Predicates::True.new }
27
+ | tFALSE { Predicator::Predicates::False.new }
22
28
  ;
23
29
  logical_predicate
24
- : predicate tAND predicate { Predicator::Predicates::And.new [val[0], val[2]] }
25
- | predicate tOR predicate { Predicator::Predicates::Or.new [val[0], val[2]] }
26
- | tBANG predicate { Predicator::Predicates::Not.new val[0] }
30
+ : predicate tAND predicate { Predicator::Predicates::And.new [val[0], val[2]] }
31
+ | predicate tOR predicate { Predicator::Predicates::Or.new [val[0], val[2]] }
32
+ | tBANG predicate { Predicator::Predicates::Not.new val[0] }
27
33
  ;
28
34
  value
29
35
  : scalar
@@ -0,0 +1,23 @@
1
+ module Predicator
2
+ module Predicates
3
+ class Between
4
+ attr_reader :value, :left, :right
5
+
6
+ def initialize value, left, right
7
+ @value, @left, @right = value, left, right
8
+ end
9
+
10
+ def satisfied? context=Predicator::Context.new
11
+ context.value_for(value) >= context.value_for(left) &&
12
+ context.value_for(value) <= context.value_for(right)
13
+ end
14
+
15
+ def == other
16
+ other.kind_of?(self.class) &&
17
+ other.value == value &&
18
+ other.left == left &&
19
+ other.right == right
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Predicator
2
+ module Predicates
3
+ class Equal < Predicator::Predicates::Relation
4
+ def satisfied? context=Predicator::Context.new
5
+ context.value_for(left) == context.value_for(right)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Predicator
2
+ module Predicates
3
+ class GreaterThan < Predicator::Predicates::Relation
4
+ def satisfied? context=Predicator::Context.new
5
+ context.value_for(left) > context.value_for(right)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Predicator
2
+ module Predicates
3
+ class GreaterThanOrEqual < Predicator::Predicates::Relation
4
+ def satisfied? context=Predicator::Context.new
5
+ context.value_for(left) >= context.value_for(right)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Predicator
2
+ module Predicates
3
+ class LessThan < Predicator::Predicates::Relation
4
+ def satisfied? context=Predicator::Context.new
5
+ context.value_for(left) < context.value_for(right)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Predicator
2
+ module Predicates
3
+ class LessThanOrEqual < Predicator::Predicates::Relation
4
+ def satisfied? context=Predicator::Context.new
5
+ context.value_for(left) <= context.value_for(right)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Predicator
2
+ module Predicates
3
+ class NotEqual < Predicator::Predicates::Relation
4
+ def satisfied? context=Predicator::Context.new
5
+ context.value_for(left) != context.value_for(right)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,16 +1,12 @@
1
1
  module Predicator
2
2
  module Predicates
3
- class Equals
3
+ class Relation
4
4
  attr_reader :left, :right
5
5
 
6
6
  def initialize left, right
7
7
  @left, @right = left, right
8
8
  end
9
9
 
10
- def satisfied? context=Predicator::Context.new
11
- context.value_for(left) == context.value_for(right)
12
- end
13
-
14
10
  def == other
15
11
  other.kind_of?(self.class) &&
16
12
  other.left == left &&
@@ -9,7 +9,7 @@ module Predicator
9
9
 
10
10
  def value_in context
11
11
  entity_name = model.to_s
12
- entity = context.entities[model]
12
+ entity = context.bindings[model]
13
13
  if entity.nil?
14
14
  raise ArgumentError, "Unknown entity #{entity_name}"
15
15
  else
@@ -1,3 +1,3 @@
1
1
  module Predicator
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: predicator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JohnnyT
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-22 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -102,10 +102,17 @@ files:
102
102
  - lib/predicator/parser.rb
103
103
  - lib/predicator/parser.y
104
104
  - lib/predicator/predicates/and.rb
105
- - lib/predicator/predicates/equals.rb
105
+ - lib/predicator/predicates/between.rb
106
+ - lib/predicator/predicates/equal.rb
106
107
  - lib/predicator/predicates/false.rb
108
+ - lib/predicator/predicates/greater_than.rb
109
+ - lib/predicator/predicates/greater_than_or_equal.rb
110
+ - lib/predicator/predicates/less_than.rb
111
+ - lib/predicator/predicates/less_than_or_equal.rb
107
112
  - lib/predicator/predicates/not.rb
113
+ - lib/predicator/predicates/not_equal.rb
108
114
  - lib/predicator/predicates/or.rb
115
+ - lib/predicator/predicates/relation.rb
109
116
  - lib/predicator/predicates/true.rb
110
117
  - lib/predicator/variable.rb
111
118
  - lib/predicator/version.rb