range_dsl 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 akimatter
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = range_dsl
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 akimatter. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "range_dsl"
8
+ gem.summary = %Q{range_dsl provides easy open range and ranges with complex conditions}
9
+ gem.description = %Q{range_dsl provides easy open range and ranges with complex conditions}
10
+ gem.email = "akm2000@gmail.com"
11
+ gem.homepage = "http://github.com/akm/range_dsl"
12
+ gem.authors = ["akimatter"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ begin
36
+ require 'reek/adapters/rake_task'
37
+ Reek::RakeTask.new do |t|
38
+ t.fail_on_error = true
39
+ t.verbose = false
40
+ t.source_files = 'lib/**/*.rb'
41
+ end
42
+ rescue LoadError
43
+ task :reek do
44
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
45
+ end
46
+ end
47
+
48
+ begin
49
+ require 'roodi'
50
+ require 'roodi_task'
51
+ RoodiTask.new do |t|
52
+ t.verbose = false
53
+ end
54
+ rescue LoadError
55
+ task :roodi do
56
+ abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
57
+ end
58
+ end
59
+
60
+ task :default => :spec
61
+
62
+ require 'rake/rdoctask'
63
+ Rake::RDocTask.new do |rdoc|
64
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
65
+
66
+ rdoc.rdoc_dir = 'rdoc'
67
+ rdoc.title = "range_dsl #{version}"
68
+ rdoc.rdoc_files.include('README*')
69
+ rdoc.rdoc_files.include('lib/**/*.rb')
70
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,51 @@
1
+ require 'range_dsl'
2
+
3
+ module RangeDsl
4
+ module ConnectionExp
5
+ module Client
6
+ def and(right)
7
+ And.new(self, right)
8
+ end
9
+ def or(right)
10
+ Or.new(self, right)
11
+ end
12
+ alias_method :&, :and
13
+ alias_method :|, :or
14
+ end
15
+
16
+ class Base
17
+ include Client
18
+
19
+ attr_accessor :left, :right
20
+ def initialize(left, right)
21
+ @left, @right = left, right # P, Q
22
+ end
23
+
24
+ def inspect
25
+ left_str = (require_brace?(@left) ? '(%s)' : '%s') % @left.inspect
26
+ right_str = (require_brace?(@right) ? '(%s)' : '%s') % @right.inspect
27
+ "#{left_str} #{name_for_inspect} #{right_str}"
28
+ end
29
+
30
+ private
31
+ def require_brace?(other)
32
+ return false unless other.is_a?(ConnectionExp::Base)
33
+ other.class != self.class
34
+ end
35
+ end
36
+
37
+ class And < Base
38
+ def name_for_inspect; "&"; end
39
+ def include?(v)
40
+ left.include?(v) && right.include?(v)
41
+ end
42
+ end
43
+
44
+ class Or < Base
45
+ def name_for_inspect; "|"; end
46
+ def include?(v)
47
+ left.include?(v) || right.include?(v)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ require 'range_dsl'
2
+
3
+ module RangeDsl
4
+ module ContainerExp
5
+ class Base
6
+ include ConnectionExp::Client
7
+
8
+ attr_accessor :values
9
+ def initialize(*args)
10
+ @values = (args.length == 1 && args.first.is_a?(Array)) ? args.first : args
11
+ end
12
+
13
+ def inspect
14
+ args = @values.inspect.gsub(/^\[|\]$/, '')
15
+ "#{name_for_inspect}(#{args})"
16
+ end
17
+ end
18
+
19
+ class Any < Base
20
+ def name_for_inspect; "any"; end
21
+ def include?(v)
22
+ @values.any?{|value| RangeDsl.include?(value, v) }
23
+ end
24
+ end
25
+
26
+ class All < Base
27
+ def name_for_inspect; "all"; end
28
+ def include?(v)
29
+ @values.all?{|value| RangeDsl.include?(value, v) }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ require 'range_dsl'
2
+
3
+ module RangeDsl
4
+ module ExactExp
5
+ class Equal
6
+ include ConnectionExp::Client
7
+
8
+ attr_accessor :value
9
+ def initialize(value)
10
+ @value = value
11
+ end
12
+
13
+ def include?(v)
14
+ RangeDsl.equal_with_considering_numeric(@value, v)
15
+ end
16
+
17
+ def inspect
18
+ "eq(#{@value.inspect})"
19
+ end
20
+ end
21
+
22
+ class NotEqual < Equal
23
+ def include?(v)
24
+ !super
25
+ end
26
+
27
+ def inspect
28
+ "neq(#{@value.inspect})"
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ require 'range_dsl'
2
+
3
+ module RangeDsl
4
+ module FilterExp
5
+ class Invert
6
+ include ConnectionExp::Client
7
+
8
+ attr_accessor :src
9
+ def initialize(src)
10
+ @src = src
11
+ end
12
+
13
+ def include?(v)
14
+ !src.include?(v)
15
+ end
16
+
17
+ def inspect
18
+ "not_be(#{@src.inspect})"
19
+ end
20
+ end
21
+
22
+ class Func
23
+ include ConnectionExp::Client
24
+
25
+ def initialize(block_str = nil, &block)
26
+ @block_str = block_str
27
+ @block = block
28
+ end
29
+
30
+ def include?(v)
31
+ !!@block.call(v)
32
+ end
33
+
34
+ def inspect
35
+ "func" << (@block_str ? "(#{@block_str.inspect})" : '{}')
36
+ end
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,57 @@
1
+ require 'range_dsl'
2
+
3
+ module RangeDsl
4
+ module OpenRangeExp
5
+ POSITIVE_INFINITY = 1.0/0
6
+ NEGATIVE_INFINITY = -1.0/0
7
+
8
+ class Base
9
+ include ConnectionExp::Client
10
+
11
+ attr_accessor :value
12
+ def initialize(value)
13
+ @value = value
14
+ end
15
+
16
+ def include?(v)
17
+ to_range.include?(v)
18
+ end
19
+
20
+ def inspect
21
+ "#{name_for_inspect}(#{@value.inspect})"
22
+ end
23
+ end
24
+
25
+ class GreaterThanEqual < Base
26
+ def name_for_inspect; "gte"; end
27
+ def to_range
28
+ @range ||= (@value..POSITIVE_INFINITY)
29
+ end
30
+ end
31
+
32
+ class GreaterThan < GreaterThanEqual
33
+ def name_for_inspect; "gt"; end
34
+ def include?(v)
35
+ return false if RangeDsl.equal_with_considering_numeric(@value, v)
36
+ to_range.include?(v)
37
+ end
38
+ end
39
+
40
+ class LessThanEqual < Base
41
+ def name_for_inspect; "lte"; end
42
+ def to_range
43
+ @range ||= (NEGATIVE_INFINITY..@value)
44
+ end
45
+ end
46
+
47
+ class LessThan < Base
48
+ def name_for_inspect; "lt"; end
49
+ def to_range
50
+ @range ||= (NEGATIVE_INFINITY...@value)
51
+ end
52
+ end
53
+
54
+
55
+ end
56
+ end
57
+
data/lib/range_dsl.rb ADDED
@@ -0,0 +1,51 @@
1
+ module RangeDsl
2
+
3
+ autoload :OpenRangeExp, 'range_dsl/open_range_exp'
4
+ autoload :ExactExp, 'range_dsl/exact_exp'
5
+ autoload :FilterExp, 'range_dsl/filter_exp'
6
+ autoload :ConnectionExp, 'range_dsl/connection_exp'
7
+ autoload :ContainerExp, 'range_dsl/container_exp'
8
+
9
+ def greater_than_equal(v); OpenRangeExp::GreaterThanEqual.new(v); end
10
+ def greater_than(v) ; OpenRangeExp::GreaterThan.new(v); end
11
+ def less_than_equal(v) ; OpenRangeExp::LessThanEqual.new(v); end
12
+ def less_than(v) ; OpenRangeExp::LessThan.new(v); end
13
+ def equal(v) ; ExactExp::Equal.new(v); end
14
+ def not_equal(v); ExactExp::NotEqual.new(v); end
15
+ def invert(exp) ; FilterExp::Invert.new(exp); end
16
+ def any(*args); ContainerExp::Any.new(*args); end
17
+ def all(*args); ContainerExp::All.new(*args); end
18
+
19
+ def func(block_str = nil, &block)
20
+ block ||= instance_eval("lambda " << block_str)
21
+ FilterExp::Func.new(block_str, &block)
22
+ end
23
+
24
+ alias_method :gte, :greater_than_equal
25
+ alias_method :gt, :greater_than
26
+ alias_method :lte, :less_than_equal
27
+ alias_method :lt, :less_than
28
+ alias_method :eq, :equal
29
+ alias_method :neq, :not_equal
30
+ alias_method :not_be, :invert
31
+ alias_method :nb, :invert
32
+
33
+ class << self
34
+ def include?(exp, v)
35
+ if exp.is_a?(Array)
36
+ exp.any?{|e| include?(e, v)}
37
+ elsif exp.respond_to?(:include?)
38
+ exp.include?(v)
39
+ else
40
+ exp == v
41
+ end
42
+ end
43
+
44
+ def equal_with_considering_numeric(left, right)
45
+ return true if left == right
46
+ return true if left.is_a?(Numeric) && right.is_a?(Numeric) && (left.to_f == right.to_f)
47
+ false
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,312 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe "RangeDsl" do
5
+ before(:all) do
6
+ @context = Object.new
7
+ @context.extend(RangeDsl)
8
+ end
9
+
10
+ describe "introduction" do
11
+ it "1,2と5以上はtrue" do
12
+ r = @context.instance_eval do
13
+ any 1, 2, gte(5)
14
+ end
15
+ r.include?(-10000).should == false
16
+ r.include?(0).should == false
17
+ r.include?(1).should == true
18
+ r.include?(2).should == true
19
+ r.include?(3).should == false
20
+ r.include?(4).should == false
21
+ r.include?(5).should == true
22
+ r.include?(6).should == true
23
+ r.include?(10000).should == true
24
+ end
25
+ end
26
+
27
+ describe "easy open range" do
28
+ describe "gte" do
29
+ [:gte, :greater_than_equal].each do |operator|
30
+ it operator do
31
+ @r1 = @context.send(operator, 100)
32
+ @r1.include?(99).should == false
33
+ @r1.include?(100).should == true
34
+ @r1.include?(100.0).should == true
35
+ @r1.include?(1234567890).should == true
36
+ @r1.inspect.should == "gte(100)"
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "gt" do
42
+ [:gt, :greater_than].each do |operator|
43
+ it operator do
44
+ @r1 = @context.send(operator, 100)
45
+ @r1.include?(99).should == false
46
+ @r1.include?(100).should == false
47
+ @r1.include?(100.0).should == false
48
+ @r1.include?(1234567890).should == true
49
+ @r1.inspect.should == "gt(100)"
50
+ end
51
+ end
52
+ end
53
+
54
+ describe "lte" do
55
+ [:lte, :less_than_equal].each do |operator|
56
+ it operator do
57
+ @r1 = @context.send(operator, 100)
58
+ @r1.include?(-1234567890).should == true
59
+ @r1.include?(99).should == true
60
+ @r1.include?(99.99).should == true
61
+ @r1.include?(100).should == true
62
+ @r1.include?(100.0).should == true
63
+ @r1.include?(100.000001).should == false
64
+ @r1.include?(101).should == false
65
+ @r1.inspect.should == "lte(100)"
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "lt" do
71
+ [:lt, :less_than].each do |operator|
72
+ it operator do
73
+ @r1 = @context.send(operator, 100)
74
+ @r1.include?(-1234567890).should == true
75
+ @r1.include?(99).should == true
76
+ @r1.include?(99.99).should == true
77
+ @r1.include?(100).should == false
78
+ @r1.include?(100.0).should == false
79
+ @r1.include?(100.000001).should == false
80
+ @r1.include?(101).should == false
81
+ @r1.inspect.should == "lt(100)"
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "just equal, or just not equal" do
88
+ describe "eq" do
89
+ [:eq, :equal].each do |operator|
90
+ it operator do
91
+ @r1 = @context.send(operator, 100)
92
+ @r1.include?(99).should == false
93
+ @r1.include?(99.9999).should == false
94
+ @r1.include?(100.0).should == true
95
+ @r1.include?(100).should == true
96
+ @r1.include?(100.0001).should == false
97
+ @r1.include?(101).should == false
98
+ @r1.inspect.should == "eq(100)"
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "lt" do
104
+ [:neq, :not_equal].each do |operator|
105
+ it operator do
106
+ @r1 = @context.send(operator, 100)
107
+ @r1.include?(99).should == true
108
+ @r1.include?(99.9999).should == true
109
+ @r1.include?(100.0).should == false
110
+ @r1.include?(100).should == false
111
+ @r1.include?(100.0001).should == true
112
+ @r1.include?(101).should == true
113
+ @r1.inspect.should == "neq(100)"
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "included in an array" do
120
+ describe "any" do
121
+ ["any(3, 7)", "any [3, 7]"].each do |dsl|
122
+ it dsl do
123
+ @r1 = @context.instance_eval(dsl)
124
+ @r1.include?(2).should == false
125
+ @r1.include?(2.9).should == false
126
+ @r1.include?(3.0).should == true
127
+ @r1.include?(3).should == true
128
+ @r1.include?(3.1).should == false
129
+ @r1.include?(4).should == false
130
+ @r1.include?(5).should == false
131
+ @r1.include?(6).should == false
132
+ @r1.include?(6.9).should == false
133
+ @r1.include?(7.0).should == true
134
+ @r1.include?(7).should == true
135
+ @r1.include?(7.1).should == false
136
+ @r1.include?(8).should == false
137
+ @r1.inspect.should == "any(3, 7)"
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+
144
+ describe "not with other expression" do
145
+ it "not_be equal(100)" do
146
+ r1 = @context.instance_eval do
147
+ not_be(equal(100))
148
+ end
149
+ r1.include?(99).should == true
150
+ r1.include?(99.9).should == true
151
+ r1.include?(100).should == false
152
+ r1.include?(100.0).should == false
153
+ r1.include?(100.1).should == true
154
+ r1.include?(101).should == true
155
+ r1.inspect.should == "not_be(eq(100))"
156
+ end
157
+ end
158
+
159
+
160
+ describe "complex pattern" do
161
+ describe "gt(3) & lt(6)" do
162
+ ["gt(3).and(lt(6))", "gt(3) & lt(6)"].each do |dsl|
163
+ it dsl do
164
+ @r2 = @context.instance_eval(dsl)
165
+ @r2.include?(2).should == false
166
+ @r2.include?(2.999).should == false
167
+ @r2.include?(3).should == false
168
+ @r2.include?(3.0).should == false
169
+ @r2.include?(3.1).should == true
170
+ @r2.include?(4).should == true
171
+ @r2.include?(5).should == true
172
+ @r2.include?(5.9).should == true
173
+ @r2.include?(6.0).should == false
174
+ @r2.include?(6).should == false
175
+ @r2.include?(6.1).should == false
176
+ @r2.include?(7).should == false
177
+ @r2.inspect.should == "gt(3) & lt(6)"
178
+ end
179
+ end
180
+ end
181
+
182
+ describe "gte(3) & lte(6)" do
183
+ {
184
+ "gte(3).and(lte(6))" => "gte(3) & lte(6)",
185
+ "gte(3) & lte(6)" => "gte(3) & lte(6)",
186
+ "all(gte(3), lte(6))" => "all(gte(3), lte(6))", # allはandの代わりに使えます
187
+ "all [gte(3), lte(6)]" => "all(gte(3), lte(6))", # allはandの代わりに使えます
188
+ }.each do |dsl, inspection|
189
+ it dsl do
190
+ @r2 = @context.instance_eval(dsl)
191
+ @r2.include?(2).should == false
192
+ @r2.include?(2.999).should == false
193
+ @r2.include?(3).should == true
194
+ @r2.include?(3.0).should == true
195
+ @r2.include?(3.1).should == true
196
+ @r2.include?(4).should == true
197
+ @r2.include?(5).should == true
198
+ @r2.include?(5.9).should == true
199
+ @r2.include?(6.0).should == true
200
+ @r2.include?(6).should == true
201
+ @r2.include?(6.1).should == false
202
+ @r2.include?(7).should == false
203
+ @r2.inspect.should == inspection
204
+ end
205
+ end
206
+ end
207
+
208
+ describe "lt(3) | gt(6)" do
209
+ {
210
+ "lt(3).or(gt(6))" => "lt(3) | gt(6)",
211
+ "lt(3) | gt(6)" => "lt(3) | gt(6)",
212
+ "any(lt(3), gt(6))" => "any(lt(3), gt(6))", # anyはorの代わりに使えます
213
+ "any [lt(3), gt(6)]" => "any(lt(3), gt(6))", # anyはorの代わりに使えます
214
+ }.each do |dsl, inspection|
215
+ it dsl do
216
+ @r2 = @context.instance_eval(dsl)
217
+ @r2.include?(2).should == true
218
+ @r2.include?(2.999).should == true
219
+ @r2.include?(3).should == false
220
+ @r2.include?(3.0).should == false
221
+ @r2.include?(3.1).should == false
222
+ @r2.include?(4).should == false
223
+ @r2.include?(5).should == false
224
+ @r2.include?(5.9).should == false
225
+ @r2.include?(6.0).should == false
226
+ @r2.include?(6).should == false
227
+ @r2.include?(6.1).should == true
228
+ @r2.include?(7).should == true
229
+ @r2.inspect.should == inspection
230
+ end
231
+ end
232
+ end
233
+
234
+ describe "lte(3) | gte(6)" do
235
+ [
236
+ "lte(3).or(gte(6))",
237
+ "lte(3) | gte(6)",
238
+ # not_be を使う
239
+ "not_be(gt(3) & lt(6))",
240
+ "not_be(gt(3).and(lt(6)))",
241
+ # 更にド・モルガンの法則で展開
242
+ "not_be(gt(3)) | not_be(lt(6))",
243
+ "not_be(gt(3)).or(not_be(lt(6)))",
244
+ ].each do |dsl|
245
+ it dsl do
246
+ @r2 = @context.instance_eval(dsl)
247
+ @r2.include?(2).should == true
248
+ @r2.include?(2.999).should == true
249
+ @r2.include?(3).should == true
250
+ @r2.include?(3.0).should == true
251
+ @r2.include?(3.1).should == false
252
+ @r2.include?(4).should == false
253
+ @r2.include?(5).should == false
254
+ @r2.include?(5.9).should == false
255
+ @r2.include?(6.0).should == true
256
+ @r2.include?(6).should == true
257
+ @r2.include?(6.1).should == true
258
+ @r2.include?(7).should == true
259
+ end
260
+ end
261
+ end
262
+ end
263
+
264
+ describe "dynamic compare" do
265
+ describe "with Proc" do
266
+ it "1以上の奇数" do
267
+ r1 = @context.instance_eval{ gte(1) & func{|v| v % 2 == 1} }
268
+ r1.include?(-3).should == false
269
+ r1.include?(-1).should == false
270
+ r1.include?(0).should == false
271
+ r1.include?(1).should == true
272
+ r1.include?(2).should == false
273
+ r1.include?(3).should == true
274
+ r1.inspect.should == "gte(1) & func{}"
275
+ end
276
+
277
+ it "動的なブロックはinspectで出力できないので、文字列でも渡せるように" do
278
+ r1 = @context.instance_eval{ gte(1) & func("{|v| v % 2 == 1}") }
279
+ r1.include?(-3).should == false
280
+ r1.include?(-1).should == false
281
+ r1.include?(0).should == false
282
+ r1.include?(1).should == true
283
+ r1.include?(2).should == false
284
+ r1.include?(3).should == true
285
+ r1.inspect.should == "gte(1) & func(\"{|v| v % 2 == 1}\")"
286
+ end
287
+ end
288
+ end
289
+
290
+ describe "complex inspection" do
291
+ it "lt(3) | gt(30) | any(2, 14, 36)" do
292
+ r2 = @context.instance_eval("lt(3) | gt(30) | any(12, 14, 16)")
293
+ r2.inspect.should == "lt(3) | gt(30) | any(12, 14, 16)"
294
+ end
295
+
296
+ it "gte(3) & lt(10) & any(2, 4, 6)" do
297
+ r2 = @context.instance_eval("gte(3) & lt(10) & any(2, 4, 6)")
298
+ r2.inspect.should == "gte(3) & lt(10) & any(2, 4, 6)"
299
+ end
300
+
301
+ it "(lt(3) | gt(30)) & any(2, 14, 36)" do
302
+ r2 = @context.instance_eval("(lt(3) | gt(30)) & any(2, 14, 36)")
303
+ r2.inspect.should == "(lt(3) | gt(30)) & any(2, 14, 36)"
304
+ end
305
+
306
+ it "lt(3) & (gt(30) | any(2, 14, 36))" do
307
+ r2 = @context.instance_eval("lt(3) & (gt(30) | any(2, 14, 36))")
308
+ r2.inspect.should == "lt(3) & (gt(30) | any(2, 14, 36))"
309
+ end
310
+ end
311
+
312
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'range_dsl'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: range_dsl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - akimatter
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-18 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ description: range_dsl provides easy open range and ranges with complex conditions
38
+ email: akm2000@gmail.com
39
+ executables: []
40
+
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - LICENSE
45
+ - README.rdoc
46
+ files:
47
+ - .document
48
+ - .gitignore
49
+ - LICENSE
50
+ - README.rdoc
51
+ - Rakefile
52
+ - VERSION
53
+ - lib/range_dsl.rb
54
+ - lib/range_dsl/connection_exp.rb
55
+ - lib/range_dsl/container_exp.rb
56
+ - lib/range_dsl/exact_exp.rb
57
+ - lib/range_dsl/filter_exp.rb
58
+ - lib/range_dsl/open_range_exp.rb
59
+ - spec/range_dsl_spec.rb
60
+ - spec/spec.opts
61
+ - spec/spec_helper.rb
62
+ has_rdoc: true
63
+ homepage: http://github.com/akm/range_dsl
64
+ licenses: []
65
+
66
+ post_install_message:
67
+ rdoc_options:
68
+ - --charset=UTF-8
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.7
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: range_dsl provides easy open range and ranges with complex conditions
96
+ test_files:
97
+ - spec/range_dsl_spec.rb
98
+ - spec/spec_helper.rb