range_dsl 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/range_dsl.rb +10 -0
- data/range_dsl.gemspec +2 -2
- data/spec/range_dsl_spec.rb +19 -24
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/range_dsl.rb
CHANGED
@@ -31,6 +31,8 @@ module RangeDsl
|
|
31
31
|
alias_method :not_be, :invert
|
32
32
|
alias_method :nb, :invert
|
33
33
|
|
34
|
+
extend self
|
35
|
+
|
34
36
|
class << self
|
35
37
|
def include?(exp, v)
|
36
38
|
if exp.is_a?(Array)
|
@@ -47,6 +49,14 @@ module RangeDsl
|
|
47
49
|
return true if left.is_a?(Numeric) && right.is_a?(Numeric) && (left.to_f == right.to_f)
|
48
50
|
false
|
49
51
|
end
|
52
|
+
|
53
|
+
def compile(dsl = nil, &block)
|
54
|
+
if block
|
55
|
+
self.instance_eval(&block)
|
56
|
+
else
|
57
|
+
self.instance_eval(dsl)
|
58
|
+
end
|
59
|
+
end
|
50
60
|
end
|
51
61
|
|
52
62
|
end
|
data/range_dsl.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{range_dsl}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["akimatter"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-20}
|
13
13
|
s.description = %q{range_dsl provides easy open range and ranges with complex conditions}
|
14
14
|
s.email = %q{akm2000@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/range_dsl_spec.rb
CHANGED
@@ -2,14 +2,9 @@
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
4
|
describe "RangeDsl" do
|
5
|
-
before(:all) do
|
6
|
-
@context = Object.new
|
7
|
-
@context.extend(RangeDsl)
|
8
|
-
end
|
9
|
-
|
10
5
|
describe "introduction" do
|
11
6
|
it "1,2と5以上はtrue" do
|
12
|
-
r =
|
7
|
+
r = RangeDsl.compile do
|
13
8
|
any 1, 2, gte(5)
|
14
9
|
end
|
15
10
|
r.include?(-10000).should == false
|
@@ -28,7 +23,7 @@ describe "RangeDsl" do
|
|
28
23
|
describe "gte" do
|
29
24
|
[:gte, :greater_than_equal].each do |operator|
|
30
25
|
it operator do
|
31
|
-
@r1 =
|
26
|
+
@r1 = RangeDsl.send(operator, 100)
|
32
27
|
@r1.include?(99).should == false
|
33
28
|
@r1.include?(100).should == true
|
34
29
|
@r1.include?(100.0).should == true
|
@@ -41,7 +36,7 @@ describe "RangeDsl" do
|
|
41
36
|
describe "gt" do
|
42
37
|
[:gt, :greater_than].each do |operator|
|
43
38
|
it operator do
|
44
|
-
@r1 =
|
39
|
+
@r1 = RangeDsl.send(operator, 100)
|
45
40
|
@r1.include?(99).should == false
|
46
41
|
@r1.include?(100).should == false
|
47
42
|
@r1.include?(100.0).should == false
|
@@ -54,7 +49,7 @@ describe "RangeDsl" do
|
|
54
49
|
describe "lte" do
|
55
50
|
[:lte, :less_than_equal].each do |operator|
|
56
51
|
it operator do
|
57
|
-
@r1 =
|
52
|
+
@r1 = RangeDsl.send(operator, 100)
|
58
53
|
@r1.include?(-1234567890).should == true
|
59
54
|
@r1.include?(99).should == true
|
60
55
|
@r1.include?(99.99).should == true
|
@@ -70,7 +65,7 @@ describe "RangeDsl" do
|
|
70
65
|
describe "lt" do
|
71
66
|
[:lt, :less_than].each do |operator|
|
72
67
|
it operator do
|
73
|
-
@r1 =
|
68
|
+
@r1 = RangeDsl.send(operator, 100)
|
74
69
|
@r1.include?(-1234567890).should == true
|
75
70
|
@r1.include?(99).should == true
|
76
71
|
@r1.include?(99.99).should == true
|
@@ -88,7 +83,7 @@ describe "RangeDsl" do
|
|
88
83
|
describe "eq" do
|
89
84
|
[:eq, :equal].each do |operator|
|
90
85
|
it operator do
|
91
|
-
@r1 =
|
86
|
+
@r1 = RangeDsl.send(operator, 100)
|
92
87
|
@r1.include?(99).should == false
|
93
88
|
@r1.include?(99.9999).should == false
|
94
89
|
@r1.include?(100.0).should == true
|
@@ -103,7 +98,7 @@ describe "RangeDsl" do
|
|
103
98
|
describe "lt" do
|
104
99
|
[:neq, :not_equal].each do |operator|
|
105
100
|
it operator do
|
106
|
-
@r1 =
|
101
|
+
@r1 = RangeDsl.send(operator, 100)
|
107
102
|
@r1.include?(99).should == true
|
108
103
|
@r1.include?(99.9999).should == true
|
109
104
|
@r1.include?(100.0).should == false
|
@@ -120,7 +115,7 @@ describe "RangeDsl" do
|
|
120
115
|
describe "any" do
|
121
116
|
["any(3, 7)", "any [3, 7]"].each do |dsl|
|
122
117
|
it dsl do
|
123
|
-
@r1 =
|
118
|
+
@r1 = RangeDsl.compile(dsl)
|
124
119
|
@r1.include?(2).should == false
|
125
120
|
@r1.include?(2.9).should == false
|
126
121
|
@r1.include?(3.0).should == true
|
@@ -143,7 +138,7 @@ describe "RangeDsl" do
|
|
143
138
|
|
144
139
|
describe "not with other expression" do
|
145
140
|
it "not_be equal(100)" do
|
146
|
-
r1 =
|
141
|
+
r1 = RangeDsl.compile do
|
147
142
|
not_be(equal(100))
|
148
143
|
end
|
149
144
|
r1.include?(99).should == true
|
@@ -161,7 +156,7 @@ describe "RangeDsl" do
|
|
161
156
|
describe "gt(3) & lt(6)" do
|
162
157
|
["gt(3).and(lt(6))", "gt(3) & lt(6)"].each do |dsl|
|
163
158
|
it dsl do
|
164
|
-
@r2 =
|
159
|
+
@r2 = RangeDsl.compile(dsl)
|
165
160
|
@r2.include?(2).should == false
|
166
161
|
@r2.include?(2.999).should == false
|
167
162
|
@r2.include?(3).should == false
|
@@ -187,7 +182,7 @@ describe "RangeDsl" do
|
|
187
182
|
"all [gte(3), lte(6)]" => "all(gte(3), lte(6))", # allはandの代わりに使えます
|
188
183
|
}.each do |dsl, inspection|
|
189
184
|
it dsl do
|
190
|
-
@r2 =
|
185
|
+
@r2 = RangeDsl.compile(dsl)
|
191
186
|
@r2.include?(2).should == false
|
192
187
|
@r2.include?(2.999).should == false
|
193
188
|
@r2.include?(3).should == true
|
@@ -213,7 +208,7 @@ describe "RangeDsl" do
|
|
213
208
|
"any [lt(3), gt(6)]" => "any(lt(3), gt(6))", # anyはorの代わりに使えます
|
214
209
|
}.each do |dsl, inspection|
|
215
210
|
it dsl do
|
216
|
-
@r2 =
|
211
|
+
@r2 = RangeDsl.compile(dsl)
|
217
212
|
@r2.include?(2).should == true
|
218
213
|
@r2.include?(2.999).should == true
|
219
214
|
@r2.include?(3).should == false
|
@@ -243,7 +238,7 @@ describe "RangeDsl" do
|
|
243
238
|
"not_be(gt(3)).or(not_be(lt(6)))",
|
244
239
|
].each do |dsl|
|
245
240
|
it dsl do
|
246
|
-
@r2 =
|
241
|
+
@r2 = RangeDsl.compile(dsl)
|
247
242
|
@r2.include?(2).should == true
|
248
243
|
@r2.include?(2.999).should == true
|
249
244
|
@r2.include?(3).should == true
|
@@ -264,7 +259,7 @@ describe "RangeDsl" do
|
|
264
259
|
describe "dynamic compare" do
|
265
260
|
describe "with Proc" do
|
266
261
|
it "1以上の奇数" do
|
267
|
-
r1 =
|
262
|
+
r1 = RangeDsl.compile{ gte(1) & func{|v| v % 2 == 1} }
|
268
263
|
r1.include?(-3).should == false
|
269
264
|
r1.include?(-1).should == false
|
270
265
|
r1.include?(0).should == false
|
@@ -275,7 +270,7 @@ describe "RangeDsl" do
|
|
275
270
|
end
|
276
271
|
|
277
272
|
it "動的なブロックはinspectで出力できないので、文字列でも渡せるように" do
|
278
|
-
r1 =
|
273
|
+
r1 = RangeDsl.compile{ gte(1) & func("{|v| v % 2 == 1}") }
|
279
274
|
r1.include?(-3).should == false
|
280
275
|
r1.include?(-1).should == false
|
281
276
|
r1.include?(0).should == false
|
@@ -289,22 +284,22 @@ describe "RangeDsl" do
|
|
289
284
|
|
290
285
|
describe "complex inspection" do
|
291
286
|
it "lt(3) | gt(30) | any(2, 14, 36)" do
|
292
|
-
r2 =
|
287
|
+
r2 = RangeDsl.compile("lt(3) | gt(30) | any(12, 14, 16)")
|
293
288
|
r2.inspect.should == "lt(3) | gt(30) | any(12, 14, 16)"
|
294
289
|
end
|
295
290
|
|
296
291
|
it "gte(3) & lt(10) & any(2, 4, 6)" do
|
297
|
-
r2 =
|
292
|
+
r2 = RangeDsl.compile("gte(3) & lt(10) & any(2, 4, 6)")
|
298
293
|
r2.inspect.should == "gte(3) & lt(10) & any(2, 4, 6)"
|
299
294
|
end
|
300
295
|
|
301
296
|
it "(lt(3) | gt(30)) & any(2, 14, 36)" do
|
302
|
-
r2 =
|
297
|
+
r2 = RangeDsl.compile("(lt(3) | gt(30)) & any(2, 14, 36)")
|
303
298
|
r2.inspect.should == "(lt(3) | gt(30)) & any(2, 14, 36)"
|
304
299
|
end
|
305
300
|
|
306
301
|
it "lt(3) & (gt(30) | any(2, 14, 36))" do
|
307
|
-
r2 =
|
302
|
+
r2 = RangeDsl.compile("lt(3) & (gt(30) | any(2, 14, 36))")
|
308
303
|
r2.inspect.should == "lt(3) & (gt(30) | any(2, 14, 36))"
|
309
304
|
end
|
310
305
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: range_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- akimatter
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-20 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|