greater_less 0.1.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0fc99744d44e587e0d2318b922c499635c9fbc6a
4
+ data.tar.gz: 1556230bfdbb9f2c1925268292d19b5a6bd2a6ad
5
+ SHA512:
6
+ metadata.gz: abcc7c867a4678bc6ff1ba99ec1862c59b47aa6cb6343472b1607c3616a94b31ca3cbb8917c060e707fe1715f5e56a07876745910e87104a9f59454beaa1c9d5
7
+ data.tar.gz: 376abc512619a5810c860ce2fc136ef59b3688d20f2bd48387f62f70527b2f56e2613f199e2601f5e1a2fe150360859a0b6f267fcef3f391ec9a5751c478d43b
data/.travis.yml CHANGED
@@ -1,9 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - jruby-18mode # JRuby in 1.8 mode
7
- - jruby-19mode # JRuby in 1.9 mode
8
- - rbx-18mode
9
- - rbx-19mode
3
+ - 2.3.1
4
+ - 2.2.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 1.0.0 / 2016-09-28
2
+
3
+ * Dropped support for ruby < 2.2
data/Gemfile CHANGED
@@ -1,16 +1,12 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
2
 
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
3
  group :development, :test do
4
+ gem 'rake'
9
5
  gem 'rdoc'
10
6
  gem 'bundler'
11
- gem 'jeweler'
12
- gem 'rspec'
13
- gem 'shoulda-matchers'
14
- # gem "rcov", :platforms => :ruby_18
15
- gem 'simplecov', :require => false, :platforms => :ruby_19
7
+ gem 'rspec', '~> 3.4'
8
+ gem 'shoulda-matchers', '~> 2.8'
9
+ gem 'simplecov', :require => false
10
+ gem 'pry'
11
+ gem 'andand'
16
12
  end
data/Gemfile.lock CHANGED
@@ -1,39 +1,64 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.3)
5
- git (1.2.5)
6
- jeweler (1.8.3)
7
- bundler (~> 1.0)
8
- git (>= 1.2.5)
9
- rake
10
- rdoc
11
- json (1.6.5)
12
- multi_json (1.2.0)
13
- rake (0.9.2.2)
14
- rdoc (3.12)
4
+ activesupport (5.0.0.1)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (~> 0.7)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ andand (1.3.3)
10
+ coderay (1.1.1)
11
+ concurrent-ruby (1.0.2)
12
+ diff-lcs (1.2.5)
13
+ docile (1.1.5)
14
+ i18n (0.7.0)
15
+ json (1.8.3)
16
+ method_source (0.8.2)
17
+ minitest (5.9.1)
18
+ pry (0.10.4)
19
+ coderay (~> 1.1.0)
20
+ method_source (~> 0.8.1)
21
+ slop (~> 3.4)
22
+ rake (11.3.0)
23
+ rdoc (4.2.2)
15
24
  json (~> 1.4)
16
- rspec (2.8.0)
17
- rspec-core (~> 2.8.0)
18
- rspec-expectations (~> 2.8.0)
19
- rspec-mocks (~> 2.8.0)
20
- rspec-core (2.8.0)
21
- rspec-expectations (2.8.0)
22
- diff-lcs (~> 1.1.2)
23
- rspec-mocks (2.8.0)
24
- shoulda-matchers (1.0.0)
25
- simplecov (0.6.1)
26
- multi_json (~> 1.0)
27
- simplecov-html (~> 0.5.3)
28
- simplecov-html (0.5.3)
25
+ rspec (3.5.0)
26
+ rspec-core (~> 3.5.0)
27
+ rspec-expectations (~> 3.5.0)
28
+ rspec-mocks (~> 3.5.0)
29
+ rspec-core (3.5.3)
30
+ rspec-support (~> 3.5.0)
31
+ rspec-expectations (3.5.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.5.0)
34
+ rspec-mocks (3.5.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.5.0)
37
+ rspec-support (3.5.0)
38
+ shoulda-matchers (2.8.0)
39
+ activesupport (>= 3.0.0)
40
+ simplecov (0.12.0)
41
+ docile (~> 1.1.0)
42
+ json (>= 1.8, < 3)
43
+ simplecov-html (~> 0.10.0)
44
+ simplecov-html (0.10.0)
45
+ slop (3.6.0)
46
+ thread_safe (0.3.5)
47
+ tzinfo (1.2.2)
48
+ thread_safe (~> 0.1)
29
49
 
30
50
  PLATFORMS
31
51
  ruby
32
52
 
33
53
  DEPENDENCIES
54
+ andand
34
55
  bundler
35
- jeweler
56
+ pry
57
+ rake
36
58
  rdoc
37
- rspec
38
- shoulda-matchers
59
+ rspec (~> 3.4)
60
+ shoulda-matchers (~> 2.8)
39
61
  simplecov
62
+
63
+ BUNDLED WITH
64
+ 1.13.1
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # GreaterLess
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/esposito/greater_less.png)](http://travis-ci.org/esposito/greater_less)
3
+ [![Build Status](https://travis-ci.org/roqua/greater_less.svg)](https://travis-ci.org/roqua/greater_less)
4
+ [![Dependency Status](https://gemnasium.com/badges/github.com/roqua/greater_less.svg)](https://gemnasium.com/github.com/roqua/greater_less)
4
5
 
5
6
  The GreaterLess gem can be used to generate objects that represent
6
7
  halfopen intervals, but transparently behave as Ruby Floats.
@@ -47,7 +48,7 @@ Now when a string starts with a greater or less sign (like for instance
47
48
  `"> 3.45"`), the `#to_f` method converts it to a GreaterLess object
48
49
  instead of the value `0.0`.
49
50
 
50
- Of course you can opt to create GreaterLess objects using `initialize` directly, like so:
51
+ Alternatively you can opt to create GreaterLess objects using `initialize` directly, like so:
51
52
 
52
53
  ```ruby
53
54
  value = GreaterLess.new("> 3.45")
@@ -122,8 +123,9 @@ In many cases it makes no sense to apply the operators +, -, * or / on
122
123
  a pair of GreaterLess objects, so when this happens an exception is
123
124
  raised for now.
124
125
 
125
- All other methods are simply passed to the Float value the GreaterLess
126
- object contains, so that it transparently acts like a Float.
126
+ All other methods are delegated to the Float value the GreaterLess
127
+ object contains, so that it transparently acts like a Float. This means you should be careful when using methods like
128
+ `abs` or `round` since they return the result from the underlying Float and bypass the GreaterLess behavior.
127
129
 
128
130
  ## Contributing to greater_less
129
131
 
@@ -137,6 +139,4 @@ object contains, so that it transparently acts like a Float.
137
139
 
138
140
  ## Copyright
139
141
 
140
- Copyright (c) 2012 Samuel Esposito. See LICENSE.txt for
141
- further details.
142
-
142
+ Copyright (c) 2016 Samuel Esposito, Jorn van de Beek. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -10,39 +10,16 @@ rescue Bundler::BundlerError => e
10
10
  exit e.status_code
11
11
  end
12
12
 
13
- require 'rake'
14
-
15
- require 'jeweler'
16
- Jeweler::Tasks.new do |gem|
17
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
- gem.name = "greater_less"
19
- gem.homepage = "http://github.com/esposito/greater_less"
20
- gem.license = "MIT"
21
- gem.summary = %Q{Gem for handling floating point half-open intervals}
22
- gem.description = %Q{The GreaterLess Gem allows for making comparisons between floats and half-open intervals and apply simple arithmetics to the intervals preserving their mathematical meaning.}
23
- gem.email = "s.esposito@roqua.nl"
24
- gem.authors = ["Samuel Esposito"]
25
- # dependencies defined in Gemfile
26
- end
27
- Jeweler::RubygemsDotOrgTasks.new
28
-
29
13
  require 'rspec/core'
30
14
  require 'rspec/core/rake_task'
31
15
  RSpec::Core::RakeTask.new(:spec) do |spec|
32
16
  spec.pattern = FileList['spec/**/*_spec.rb']
33
17
  end
34
18
 
35
- if RUBY_VERSION =~ /^1\.9/
36
- desc "Code coverage detail"
37
- task :simplecov do
38
- ENV['COVERAGE'] = "true"
39
- Rake::Task['spec'].execute
40
- end
41
- # else
42
- # RSpec::Core::RakeTask.new(:rcov) do |spec|
43
- # spec.pattern = 'spec/**/*_spec.rb'
44
- # spec.rcov = true
45
- # end
19
+ desc "Code coverage detail"
20
+ task :simplecov do
21
+ ENV['COVERAGE'] = "true"
22
+ Rake::Task['spec'].execute
46
23
  end
47
24
 
48
25
  task :default => :spec
data/greater_less.gemspec CHANGED
@@ -1,17 +1,15 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
3
  Gem::Specification.new do |s|
7
4
  s.name = "greater_less"
8
- s.version = "0.1.1"
5
+ s.version = "1.0.0"
9
6
 
7
+ s.required_ruby_version = '>= 2.2.0'
10
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Samuel Esposito"]
12
- s.date = "2012-04-03"
9
+ s.authors = ["Samuel Esposito", "Jorn van de Beek"]
10
+ s.date = Date.today.to_s
13
11
  s.description = "The GreaterLess Gem allows for making comparisons between floats and half-open intervals and apply simple arithmetics to the intervals preserving their mathematical meaning."
14
- s.email = "s.esposito@roqua.nl"
12
+ s.email = "support@roqua.nl"
15
13
  s.extra_rdoc_files = [
16
14
  "LICENSE.txt",
17
15
  "README.md"
@@ -24,45 +22,24 @@ Gem::Specification.new do |s|
24
22
  "Gemfile.lock",
25
23
  "LICENSE.txt",
26
24
  "README.md",
25
+ "CHANGELOG.md",
27
26
  "Rakefile",
28
- "VERSION",
29
27
  "greater_less.gemspec",
30
28
  "lib/greater_less.rb",
31
29
  "lib/greater_less/string_extension.rb",
32
30
  "spec/greater_less_spec.rb",
33
31
  "spec/spec_helper.rb"
34
32
  ]
35
- s.homepage = "http://github.com/esposito/greater_less"
33
+ s.homepage = "http://github.com/roqua/greater_less"
36
34
  s.licenses = ["MIT"]
37
35
  s.require_paths = ["lib"]
38
- s.rubygems_version = "1.8.15"
39
36
  s.summary = "Gem for handling floating point half-open intervals"
40
37
 
41
- if s.respond_to? :specification_version then
42
- s.specification_version = 3
43
-
44
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
- s.add_development_dependency(%q<rdoc>, [">= 0"])
46
- s.add_development_dependency(%q<bundler>, [">= 0"])
47
- s.add_development_dependency(%q<jeweler>, [">= 0"])
48
- s.add_development_dependency(%q<rspec>, [">= 0"])
49
- s.add_development_dependency(%q<shoulda-matchers>, [">= 0"])
50
- s.add_development_dependency(%q<simplecov>, [">= 0"])
51
- else
52
- s.add_dependency(%q<rdoc>, [">= 0"])
53
- s.add_dependency(%q<bundler>, [">= 0"])
54
- s.add_dependency(%q<jeweler>, [">= 0"])
55
- s.add_dependency(%q<rspec>, [">= 0"])
56
- s.add_dependency(%q<shoulda-matchers>, [">= 0"])
57
- s.add_dependency(%q<simplecov>, [">= 0"])
58
- end
59
- else
60
- s.add_dependency(%q<rdoc>, [">= 0"])
61
- s.add_dependency(%q<bundler>, [">= 0"])
62
- s.add_dependency(%q<jeweler>, [">= 0"])
63
- s.add_dependency(%q<rspec>, [">= 0"])
64
- s.add_dependency(%q<shoulda-matchers>, [">= 0"])
65
- s.add_dependency(%q<simplecov>, [">= 0"])
66
- end
38
+ s.add_development_dependency 'rake', '~> 0'
39
+ s.add_development_dependency 'rdoc', '~> 0'
40
+ s.add_development_dependency 'bundler', '~> 0'
41
+ s.add_development_dependency 'rspec', '~> 3'
42
+ s.add_development_dependency 'shoulda-matchers', '~> 0'
43
+ s.add_development_dependency 'simplecov', '~> 0'
67
44
  end
68
45
 
data/lib/greater_less.rb CHANGED
@@ -88,13 +88,9 @@
88
88
  # All other methods are simply passed to the Float value the GreaterLess
89
89
  # object contains, so that it transparently acts like a Float.
90
90
  #
91
+ require 'delegate'
91
92
 
92
- class GreaterLess
93
- instance_methods.each do |meth|
94
- # skipping undef of methods that "may cause serious problems"
95
- undef_method(meth) if meth !~ /^(__|object_id|class)/
96
- end
97
-
93
+ class GreaterLess < Delegator
98
94
  GREATER_LESS = /^[<>] ?/
99
95
 
100
96
  #:nodoc:
@@ -123,6 +119,7 @@ class GreaterLess
123
119
  else
124
120
  raise "Can't handle #{content.class}!"
125
121
  end
122
+ super(@float)
126
123
  end
127
124
 
128
125
  def coerce(object)
@@ -133,6 +130,14 @@ class GreaterLess
133
130
  end
134
131
  end
135
132
 
133
+ # delegate any method not defined in this class to float
134
+ def __getobj__
135
+ @float
136
+ end
137
+ def __setobj__(obj)
138
+ @float = obj
139
+ end
140
+
136
141
  def sign
137
142
  @sign
138
143
  end
@@ -185,31 +190,31 @@ class GreaterLess
185
190
 
186
191
  def *(numerical)
187
192
  value, sign = if numerical.is_a? self.class
188
- raise "Can't handle #{self.class}!" if @sign
189
- [@float * numerical.value, @float > 0 ? numerical.sign : numerical.inverted_sign]
190
- else
191
- [@float * numerical, numerical > 0 ? @sign : inverted_sign]
192
- end
193
+ raise "Can't handle #{self.class}!" if @sign
194
+ [@float * numerical.value, @float > 0 ? numerical.sign : numerical.inverted_sign]
195
+ else
196
+ [@float * numerical, numerical > 0 ? @sign : inverted_sign]
197
+ end
193
198
  GreaterLess.new("#{sign} #{value}")
194
199
  end
195
200
 
196
201
  def /(numerical)
197
202
  value, sign = if numerical.is_a? self.class
198
- raise "Can't handle #{self.class}!" if @sign
199
- [@float / numerical.value, @float > 0 ? numerical.inverted_sign : numerical.sign]
200
- else
201
- [@float / numerical, numerical > 0 ? @sign : inverted_sign]
202
- end
203
+ raise "Can't handle #{self.class}!" if @sign
204
+ [@float / numerical.value, @float > 0 ? numerical.inverted_sign : numerical.sign]
205
+ else
206
+ [@float / numerical, numerical > 0 ? @sign : inverted_sign]
207
+ end
203
208
  GreaterLess.new("#{sign} #{value}")
204
209
  end
205
210
 
206
211
  def +(numerical)
207
212
  value, sign = if numerical.is_a? self.class
208
- raise "Can't handle #{self.class}!" if @sign
209
- [@float + numerical.value, numerical.sign]
210
- else
211
- [@float + numerical, @sign]
212
- end
213
+ raise "Can't handle #{self.class}!" if @sign
214
+ [@float + numerical.value, numerical.sign]
215
+ else
216
+ [@float + numerical, @sign]
217
+ end
213
218
  GreaterLess.new("#{sign} #{value}")
214
219
  end
215
220
 
@@ -234,6 +239,10 @@ class GreaterLess
234
239
  self.to_s
235
240
  end
236
241
 
242
+ def kind_of?(klass)
243
+ is_a?(klass)
244
+ end
245
+
237
246
  def is_a?(klass)
238
247
  if klass == self.class
239
248
  true
@@ -242,7 +251,8 @@ class GreaterLess
242
251
  end
243
252
  end
244
253
 
245
- def method_missing(*args)
246
- @float.send(*args)
254
+ # fixes delegator breaking andand functionality
255
+ def andand(*)
256
+ self
247
257
  end
248
- end
258
+ end
@@ -7,48 +7,48 @@ describe GreaterLess do
7
7
  subject { GreaterLess.new("> 4.5") }
8
8
 
9
9
  it "should differ from its float value" do
10
- (subject == 4.5).should be_false
11
- (subject != 4.5).should be_true
12
- (4.5 == subject).should be_false
13
- (4.5 != subject).should be_true
10
+ expect(subject == 4.5).to eq false
11
+ expect(subject != 4.5).to eq true
12
+ expect(4.5 == subject).to eq false
13
+ expect(4.5 != subject).to eq true
14
14
  end
15
15
 
16
16
  it "should be greater than its float value" do
17
- (subject > 4.5).should be_true
18
- (subject >= 4.5).should be_true
19
- (4.5 < subject).should be_true
20
- (4.5 <= subject).should be_true
17
+ expect(subject > 4.5).to eq true
18
+ expect(subject >= 4.5).to eq true
19
+ expect(4.5 < subject).to eq true
20
+ expect(4.5 <= subject).to eq true
21
21
  end
22
22
 
23
23
  it "should be greater than any value that is less than its float value" do
24
- (subject > 4.49).should be_true
25
- (subject >= 4.49).should be_true
26
- (4.49 < subject).should be_true
27
- (4.49 <= subject).should be_true
24
+ expect(subject > 4.49).to eq true
25
+ expect(subject >= 4.49).to eq true
26
+ expect(4.49 < subject).to eq true
27
+ expect(4.49 <= subject).to eq true
28
28
  end
29
29
 
30
30
  it "should not be greater than a value greater than its float value" do
31
- (subject > 4.51).should be_false
32
- (subject >= 4.51).should be_false
33
- (4.51 < subject).should be_false
34
- (4.51 <= subject).should be_false
31
+ expect(subject > 4.51).to eq false
32
+ expect(subject >= 4.51).to eq false
33
+ expect(4.51 < subject).to eq false
34
+ expect(4.51 <= subject).to eq false
35
35
  end
36
36
 
37
37
  it "should not be less than a value that is greater than its float value" do
38
- (subject < 4.51).should be_false
39
- (subject <= 4.51).should be_false
40
- (4.51 > subject).should be_false
41
- (4.51 >= subject).should be_false
38
+ expect(subject < 4.51).to eq false
39
+ expect(subject <= 4.51).to eq false
40
+ expect(4.51 > subject).to eq false
41
+ expect(4.51 >= subject).to eq false
42
42
  end
43
43
 
44
44
  it "should be greater than a GreaterLess object that has a smaller or equal value and a less sign" do
45
- (subject > GreaterLess.new("< 4.49")).should be_true
46
- (subject > GreaterLess.new("< 4.5") ).should be_true
45
+ expect(subject > GreaterLess.new("< 4.49")).to eq true
46
+ expect(subject > GreaterLess.new("< 4.5") ).to eq true
47
47
  end
48
48
 
49
49
  it "should not be greater than a GreaterLess object that has a bigger value or a greater sign" do
50
- (subject > GreaterLess.new("< 4.51")).should be_false
51
- (subject > GreaterLess.new("> 4.49")).should be_false
50
+ expect(subject > GreaterLess.new("< 4.51")).to eq false
51
+ expect(subject > GreaterLess.new("> 4.49")).to eq false
52
52
  end
53
53
  end
54
54
 
@@ -56,38 +56,38 @@ describe GreaterLess do
56
56
  subject { GreaterLess.new("<4.5") }
57
57
 
58
58
  it "should differ from its float value" do
59
- (subject == 4.5).should be_false
60
- (subject != 4.5).should be_true
61
- (4.5 == subject).should be_false
62
- (4.5 != subject).should be_true
59
+ expect(subject == 4.5).to eq false
60
+ expect(subject != 4.5).to eq true
61
+ expect(4.5 == subject).to eq false
62
+ expect(4.5 != subject).to eq true
63
63
  end
64
64
 
65
65
  it "should be less than its float value" do
66
- (subject < 4.5).should be_true
67
- (subject <= 4.5).should be_true
68
- (4.5 > subject).should be_true
69
- (4.5 >= subject).should be_true
66
+ expect(subject < 4.5).to eq true
67
+ expect(subject <= 4.5).to eq true
68
+ expect(4.5 > subject).to eq true
69
+ expect(4.5 >= subject).to eq true
70
70
  end
71
71
 
72
72
  it "should be less than any value that is greater than its float value" do
73
- (subject < 4.51).should be_true
74
- (subject <= 4.51).should be_true
75
- (4.51 > subject).should be_true
76
- (4.51 >= subject).should be_true
73
+ expect(subject < 4.51).to eq true
74
+ expect(subject <= 4.51).to eq true
75
+ expect(4.51 > subject).to eq true
76
+ expect(4.51 >= subject).to eq true
77
77
  end
78
78
 
79
79
  it "should not be less than a value less than its float value" do
80
- (subject < 4.49).should be_false
81
- (subject <= 4.49).should be_false
82
- (4.49 > subject).should be_false
83
- (4.49 >= subject).should be_false
80
+ expect(subject < 4.49).to eq false
81
+ expect(subject <= 4.49).to eq false
82
+ expect(4.49 > subject).to eq false
83
+ expect(4.49 >= subject).to eq false
84
84
  end
85
85
 
86
86
  it "should not be greater than a value that is less than its float value" do
87
- (subject > 4.49).should be_false
88
- (subject >= 4.49).should be_false
89
- (4.49 < subject).should be_false
90
- (4.49 <= subject).should be_false
87
+ expect(subject > 4.49).to eq false
88
+ expect(subject >= 4.49).to eq false
89
+ expect(4.49 < subject).to eq false
90
+ expect(4.49 <= subject).to eq false
91
91
  end
92
92
  end
93
93
 
@@ -95,7 +95,7 @@ describe GreaterLess do
95
95
  subject { GreaterLess.new("4.5") }
96
96
 
97
97
  it "should be a float" do
98
- subject.class.should == Float
98
+ expect(subject.class).to eq Float
99
99
  end
100
100
  end
101
101
  end
@@ -103,7 +103,7 @@ describe GreaterLess do
103
103
  describe ".initialize" do
104
104
  context "when it receives something different from a string or a numeric" do
105
105
  it "should raise an exception" do
106
- expect { GreaterLess.new(Object.new, true) }.to raise_error
106
+ expect { GreaterLess.new(Object.new, true) }.to raise_error('Can\'t handle Object!')
107
107
  end
108
108
  end
109
109
  end
@@ -112,173 +112,207 @@ describe GreaterLess do
112
112
  subject { GreaterLess.new(">4.5") }
113
113
 
114
114
  it "should be a float" do
115
- subject.should be_a(Float)
115
+ expect(subject).to be_a(Float)
116
116
  end
117
117
 
118
118
  it "should equal itself" do
119
- (subject == subject).should be_true
119
+ expect(subject == subject).to eq true
120
120
  end
121
121
 
122
122
  describe "#coerce" do
123
123
  it "should raise an exception if it is called on a GreaterLess object" do
124
- expect { subject.coerce(GreaterLess.new("<2.45")) }.to raise_error
124
+ expect { subject.coerce(GreaterLess.new("<2.45")) }.to raise_error('Can\'t handle GreaterLess!')
125
125
  end
126
126
  end
127
127
 
128
128
  describe "#inverted_sign" do
129
129
  it "should return a less sign when the object's sign is a greater sign" do
130
- GreaterLess.new("> 1").inverted_sign.should eq("<")
130
+ expect(GreaterLess.new("> 1").inverted_sign).to eq("<")
131
131
  end
132
132
 
133
133
  it "should return a greater sign when the object's sign is a less sign" do
134
- GreaterLess.new("< 1").inverted_sign.should eq(">")
134
+ expect(GreaterLess.new("< 1").inverted_sign).to eq(">")
135
135
  end
136
136
  end
137
137
 
138
138
  describe "#*" do
139
139
  it "should return a GreaterLess object" do
140
- (subject * 4).class.should == GreaterLess
141
- (4 * subject).class.should == GreaterLess
140
+ expect((subject * 4).class).to eq GreaterLess
141
+ expect((4 * subject).class).to eq GreaterLess
142
142
  end
143
143
 
144
144
  it "should carry out multiplication on its float value" do
145
- (subject * 4).value.should == 18
146
- (4 * subject).value.should == 18
145
+ expect((subject * 4).value).to eq 18
146
+ expect((4 * subject).value).to eq 18
147
147
  end
148
148
 
149
149
  it "should retain the object's sign when the argument is a positive numeric" do
150
- (subject * 4).sign.should == subject.sign
151
- (4 * subject).sign.should == subject.sign
150
+ expect((subject * 4).sign).to eq subject.sign
151
+ expect((4 * subject).sign).to eq subject.sign
152
152
  end
153
153
 
154
154
  it "should invert the object's sign when the argument is a negative numeric" do
155
- (subject * -4).sign.should == subject.inverted_sign
156
- (-4 * subject).sign.should == subject.inverted_sign
155
+ expect((subject * -4).sign).to eq subject.inverted_sign
156
+ expect((-4 * subject).sign).to eq subject.inverted_sign
157
157
  end
158
158
 
159
159
  it "should raise an exception when the argument is a GreaterLess object" do
160
- expect { subject * GreaterLess.new("<1.2") }.to raise_error
160
+ expect { subject * GreaterLess.new("<1.2") }.to raise_error('Can\'t handle GreaterLess!')
161
161
  end
162
162
  end
163
163
 
164
164
  describe "#/" do
165
165
  it "should return a GreaterLess object" do
166
- (subject / 4).class.should == GreaterLess
167
- (4 / subject).class.should == GreaterLess
166
+ expect((subject / 4).class).to eq GreaterLess
167
+ expect((4 / subject).class).to eq GreaterLess
168
168
  end
169
169
 
170
170
  it "should carry out division on its float value" do
171
- (subject / 4).value.should == 4.5 / 4
172
- (4 / subject).value.to_s.should == (4 / 4.5).to_s
171
+ expect((subject / 4).value).to eq 4.5 / 4
172
+ expect((4 / subject).value.to_s).to eq (4 / 4.5).to_s
173
173
  end
174
174
 
175
175
  it "should retain the object's sign when the denominator is a positive numeric" do
176
- (subject / 4).sign.should == subject.sign
176
+ expect((subject / 4).sign).to eq subject.sign
177
177
  end
178
178
 
179
179
  it "should retain the object's sign when the numerator is a negative numeric" do
180
- (-4 / subject).sign.should == subject.sign
180
+ expect((-4 / subject).sign).to eq subject.sign
181
181
  end
182
182
 
183
183
  it "should invert the object's sign when the object itself is the denominator" do
184
- (4 / subject).sign.should == subject.inverted_sign
184
+ expect((4 / subject).sign).to eq subject.inverted_sign
185
185
  end
186
186
 
187
187
  it "should invert the object's sign when the denominator is a negative numeric" do
188
- (subject / -4).sign.should == subject.inverted_sign
188
+ expect((subject / -4).sign).to eq subject.inverted_sign
189
189
  end
190
190
 
191
191
  it "should raise an exception when the argument is a GreaterLess object" do
192
- expect { subject / GreaterLess.new("<1.2") }.to raise_error
192
+ expect { subject / GreaterLess.new("<1.2") }.to raise_error('Can\'t handle GreaterLess!')
193
193
  end
194
194
  end
195
195
 
196
196
  describe "#+" do
197
197
  it "should return a GreaterLess object" do
198
- (subject + 4).class.should == GreaterLess
199
- (4 + subject).class.should == GreaterLess
198
+ expect((subject + 4).class).to eq GreaterLess
199
+ expect((4 + subject).class).to eq GreaterLess
200
200
  end
201
201
 
202
202
  it "should carry out addition on its float value" do
203
- (subject + 4).value.should == 8.5
204
- (4 + subject).value.should == 8.5
203
+ expect((subject + 4).value).to eq 8.5
204
+ expect((4 + subject).value).to eq 8.5
205
205
  end
206
206
 
207
207
  it "should retain the object's sign" do
208
- (subject + 4).sign.should == subject.sign
209
- (4 + subject).sign.should == subject.sign
208
+ expect((subject + 4).sign).to eq subject.sign
209
+ expect((4 + subject).sign).to eq subject.sign
210
210
  end
211
211
 
212
212
  it "should raise an exception when the argument is a GreaterLess object" do
213
- expect { subject + GreaterLess.new("<1.2") }.to raise_error
213
+ expect { subject + GreaterLess.new("<1.2") }.to raise_error('Can\'t handle GreaterLess!')
214
214
  end
215
215
  end
216
216
 
217
217
  describe "#-" do
218
218
  it "should return a GreaterLess object" do
219
- (subject - 4).class.should == GreaterLess
220
- (4 - subject).class.should == GreaterLess
219
+ expect((subject - 4).class).to eq GreaterLess
220
+ expect((4 - subject).class).to eq GreaterLess
221
221
  end
222
222
 
223
223
  it "should carry out subtraction on its float value" do
224
- (subject - 4).value.should == 0.5
225
- (4 - subject).value.should == -0.5
224
+ expect((subject - 4).value).to eq 0.5
225
+ expect((4 - subject).value).to eq -0.5
226
226
  end
227
227
 
228
228
  it "should retain the object's sign when a numerical is subtracted from it" do
229
- (subject - 4).sign.should == subject.sign
229
+ expect((subject - 4).sign).to eq subject.sign
230
230
  end
231
231
 
232
232
  it "should invert the object's sign when it is subtracted form a numerical" do
233
- (4 - subject).sign.should == subject.inverted_sign
233
+ expect((4 - subject).sign).to eq subject.inverted_sign
234
234
  end
235
235
 
236
236
  it "should raise an exception when the argument is a GreaterLess object" do
237
- expect { subject - GreaterLess.new("<1.2") }.to raise_error
237
+ expect { subject - GreaterLess.new("<1.2") }.to raise_error('Can\'t handle GreaterLess!')
238
238
  end
239
239
  end
240
240
 
241
241
  describe "#-@" do
242
242
  it "should return a GreaterLess object" do
243
- (-subject).class.should == GreaterLess
243
+ expect((-subject).class).to eq GreaterLess
244
244
  end
245
245
 
246
246
  it "should negate the object's value" do
247
- (-subject).value.should == -subject.value
247
+ expect((-subject).value).to eq -subject.value
248
248
  end
249
249
 
250
250
  it "should invert the object's sign" do
251
- (-subject).sign.should == subject.inverted_sign
251
+ expect((-subject).sign).to eq subject.inverted_sign
252
252
  end
253
253
  end
254
254
 
255
255
  describe "#to_f" do
256
256
  it "should return the object itself" do
257
- subject.to_f.class.should == GreaterLess
257
+ expect(subject.to_f.class).to eq GreaterLess
258
258
  end
259
259
  end
260
260
 
261
261
  describe "#to_s" do
262
262
  it "should include this sign" do
263
- subject.to_s.should == "> 4.5"
263
+ expect(subject.to_s).to eq "> 4.5"
264
264
  end
265
265
  end
266
266
 
267
267
  describe "#inspect" do
268
268
  it "should include this sign" do
269
- subject.inspect.should == "> 4.5"
269
+ expect(subject.inspect).to eq "> 4.5"
270
270
  end
271
271
  end
272
272
 
273
- describe "#is_a?" do
273
+ describe "#is_a? #kind_of?" do
274
274
  it "should acknowledge the GreaterLess class" do
275
- subject.is_a?(GreaterLess).should be_true
275
+ expect(subject.is_a? GreaterLess).to eq true
276
+ expect(subject.kind_of? GreaterLess).to eq true
277
+ # be_a actually calls kind_of instead of is_a
278
+ expect(subject).to be_a(GreaterLess)
276
279
  end
277
280
 
278
281
  it "should acknowledge the Float class" do
279
- subject.is_a?(Float).should be_true
282
+ expect(subject.is_a? Float).to eq true
283
+ expect(subject.kind_of? Float).to eq true
284
+ # be_a actually calls kind_of instead of is_a
285
+ expect(subject).to be_a(Float)
280
286
  end
281
287
  end
282
- end
283
288
 
284
- end
289
+ describe 'delegation' do
290
+ subject { GreaterLess.new('>4.5') }
291
+ it 'passes unknown methods on to the underlying float' do
292
+ # having methods like round and abs be handled on the original float is very error prone
293
+ # so we document this 'feature' here and warn people in the Readme
294
+ expect(subject.round).to eq 5
295
+ end
296
+
297
+ it 'preserves blocks' do
298
+ success = false
299
+ subject.tap do success = true end
300
+ expect(success).to eq true
301
+ end
302
+
303
+ it 'preserves blocks that also have arguments' do
304
+ steps = []
305
+ subject.step(7.5) do |i|
306
+ steps << i
307
+ end
308
+ expect(steps).to eq [4.5, 5.5, 6.5, 7.5]
309
+ end
310
+
311
+ it 'does not break andand' do
312
+ expect(subject.andand).to be_a(GreaterLess)
313
+ expect(subject.andand).to eq(subject)
314
+ expect(subject.andand.to_s).to eq('> 4.5')
315
+ end
316
+ end
317
+ end
318
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- if RUBY_VERSION =~ /^1\.9/ and ENV['COVERAGE']
2
+ if ENV['COVERAGE']
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
5
  end
@@ -21,6 +21,7 @@ end
21
21
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
22
22
  $LOAD_PATH.unshift(File.dirname(__FILE__))
23
23
  require 'rspec'
24
+ require 'andand'
24
25
  require 'greater_less'
25
26
 
26
27
  # Requires supporting files with custom matchers and macros, etc,
@@ -29,4 +30,4 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
29
30
 
30
31
  RSpec.configure do |config|
31
32
 
32
- end
33
+ end
metadata CHANGED
@@ -1,162 +1,146 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: greater_less
3
- version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Samuel Esposito
8
+ - Jorn van de Beek
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- requirement: &id001 !ruby/object:Gem::Requirement
22
- none: false
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- hash: 3
27
- segments:
28
- - 0
29
- version: "0"
30
- version_requirements: *id001
31
- name: rdoc
32
- prerelease: false
12
+ date: 2016-09-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
33
21
  type: :development
34
- - !ruby/object:Gem::Dependency
35
- requirement: &id002 !ruby/object:Gem::Requirement
36
- none: false
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- hash: 3
41
- segments:
42
- - 0
43
- version: "0"
44
- version_requirements: *id002
45
- name: bundler
46
22
  prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rdoc
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
47
35
  type: :development
48
- - !ruby/object:Gem::Dependency
49
- requirement: &id003 !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- hash: 3
55
- segments:
56
- - 0
57
- version: "0"
58
- version_requirements: *id003
59
- name: jeweler
60
36
  prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
61
49
  type: :development
62
- - !ruby/object:Gem::Dependency
63
- requirement: &id004 !ruby/object:Gem::Requirement
64
- none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
- version: "0"
72
- version_requirements: *id004
73
- name: rspec
74
50
  prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3'
75
63
  type: :development
76
- - !ruby/object:Gem::Dependency
77
- requirement: &id005 !ruby/object:Gem::Requirement
78
- none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
- version: "0"
86
- version_requirements: *id005
87
- name: shoulda-matchers
88
64
  prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: shoulda-matchers
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
89
77
  type: :development
90
- - !ruby/object:Gem::Dependency
91
- requirement: &id006 !ruby/object:Gem::Requirement
92
- none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- hash: 3
97
- segments:
98
- - 0
99
- version: "0"
100
- version_requirements: *id006
101
- name: simplecov
102
78
  prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: simplecov
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
103
91
  type: :development
104
- description: The GreaterLess Gem allows for making comparisons between floats and half-open intervals and apply simple arithmetics to the intervals preserving their mathematical meaning.
105
- email: s.esposito@roqua.nl
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: The GreaterLess Gem allows for making comparisons between floats and
99
+ half-open intervals and apply simple arithmetics to the intervals preserving their
100
+ mathematical meaning.
101
+ email: support@roqua.nl
106
102
  executables: []
107
-
108
103
  extensions: []
109
-
110
- extra_rdoc_files:
104
+ extra_rdoc_files:
111
105
  - LICENSE.txt
112
106
  - README.md
113
- files:
114
- - .document
115
- - .rspec
116
- - .travis.yml
107
+ files:
108
+ - ".document"
109
+ - ".rspec"
110
+ - ".travis.yml"
111
+ - CHANGELOG.md
117
112
  - Gemfile
118
113
  - Gemfile.lock
119
114
  - LICENSE.txt
120
115
  - README.md
121
116
  - Rakefile
122
- - VERSION
123
117
  - greater_less.gemspec
124
118
  - lib/greater_less.rb
125
119
  - lib/greater_less/string_extension.rb
126
120
  - spec/greater_less_spec.rb
127
121
  - spec/spec_helper.rb
128
- homepage: http://github.com/esposito/greater_less
129
- licenses:
122
+ homepage: http://github.com/roqua/greater_less
123
+ licenses:
130
124
  - MIT
125
+ metadata: {}
131
126
  post_install_message:
132
127
  rdoc_options: []
133
-
134
- require_paths:
128
+ require_paths:
135
129
  - lib
136
- required_ruby_version: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
139
132
  - - ">="
140
- - !ruby/object:Gem::Version
141
- hash: 3
142
- segments:
143
- - 0
144
- version: "0"
145
- required_rubygems_version: !ruby/object:Gem::Requirement
146
- none: false
147
- requirements:
133
+ - !ruby/object:Gem::Version
134
+ version: 2.2.0
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
148
137
  - - ">="
149
- - !ruby/object:Gem::Version
150
- hash: 3
151
- segments:
152
- - 0
153
- version: "0"
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
154
140
  requirements: []
155
-
156
141
  rubyforge_project:
157
- rubygems_version: 1.8.15
142
+ rubygems_version: 2.5.1
158
143
  signing_key:
159
- specification_version: 3
144
+ specification_version: 4
160
145
  summary: Gem for handling floating point half-open intervals
161
146
  test_files: []
162
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1