quantify 3.2.0 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.2.1
@@ -122,7 +122,7 @@ module Quantify
122
122
  # a unit. The unit can be a an instance of Unit::Base or the name, symbol or
123
123
  # JScience label of a known (or derivable through know units and prefixes)
124
124
  # unit
125
- def initialize(value, unit)
125
+ def initialize(value, unit = 'unity')
126
126
  if value
127
127
  @value = value.to_f
128
128
  else
@@ -291,6 +291,8 @@ module Quantify
291
291
  def <=>(other)
292
292
  raise Exceptions::InvalidArgumentError unless other.is_a? Quantity
293
293
  raise Exceptions::InvalidArgumentError unless other.unit.is_alternative_for?(unit)
294
+ return 0 if @value.nil? && (other.nil? || other.value.nil?)
295
+
294
296
  other = other.to @unit
295
297
  @value.to_f <=> other.value.to_f
296
298
  end
@@ -300,6 +302,11 @@ module Quantify
300
302
  range.cover? self
301
303
  end
302
304
 
305
+ def between?(min, max)
306
+ raise NoMethodError if @value.nil?
307
+ super(min,max)
308
+ end
309
+
303
310
  protected
304
311
 
305
312
  # Quantities must be of the same dimension in order to operate. If they are
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{quantify}
8
- s.version = "3.2.0"
8
+ s.version = "3.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrew Berkeley"]
@@ -4,6 +4,14 @@ include Quantify
4
4
 
5
5
  describe Quantity do
6
6
 
7
+ describe "#initialize" do
8
+ specify { Quantity.new(1).should eq(Quantity.new(1,'unity')) }
9
+ specify { Quantity.new(nil,nil).should eq(Quantity.new(nil,'unity')) }
10
+ specify { Quantity.new(nil,nil).should eq(Quantity.new(nil,'unity')) }
11
+ specify { Quantity.new(nil,'unity').should eq(Quantity.new(nil,'unity')) }
12
+ specify { Quantity.new(nil).should eq(Quantity.new(nil,'unity')) }
13
+ end
14
+
7
15
  it "should create a valid instance with nil values" do
8
16
  quantity = Quantity.new nil, nil
9
17
  quantity.value.should be_nil
@@ -561,29 +569,65 @@ describe Quantity do
561
569
  end
562
570
 
563
571
  context "comparing nil quantities" do
564
- specify "greater than" do
565
- lambda{Quantity.new(nil,nil) > 1.m}.should raise_error
566
- end
567
572
 
568
- specify "greater than or equals" do
569
- lambda{Quantity.new(nil,nil) >= 1.m}.should raise_error
570
- end
573
+ context "when comparing with non-nil quantities" do
574
+ specify "greater than" do
575
+ lambda{Quantity.new(nil,nil) > 1.m}.should raise_error
576
+ end
571
577
 
572
- specify "less than" do
573
- lambda{Quantity.new(nil,nil) < 1.m}.should raise_error
574
- end
578
+ specify "greater than or equals" do
579
+ lambda{Quantity.new(nil,nil) >= 1.m}.should raise_error
580
+ end
575
581
 
576
- specify "less than or equals" do
577
- lambda{Quantity.new(nil,nil) <= 1.m}.should raise_error
578
- end
582
+ specify "less than" do
583
+ lambda{Quantity.new(nil,nil) < 1.m}.should raise_error
584
+ end
585
+
586
+ specify "less than or equals" do
587
+ lambda{Quantity.new(nil,nil) <= 1.m}.should raise_error
588
+ end
589
+
590
+ specify "equals" do
591
+ lambda{Quantity.new(nil,nil) == 1.m}.should raise_error
592
+ end
579
593
 
580
- specify "equals" do
581
- lambda{Quantity.new(nil,nil) == 1.m}.should raise_error
594
+ specify "between" do
595
+ lambda{Quantity.new(nil,nil).between? 1.ft,10.m}.should raise_error NoMethodError
596
+ lambda{Quantity.new(nil,nil).between? Quantity.new(nil,nil),Quantity.new(nil,nil)}.should raise_error NoMethodError
597
+ end
598
+
599
+ specify "range" do
600
+ expect{(Quantity.new(nil)..1.kg)}.to raise_error
601
+ expect{(1.kg..Quantity.new(nil))}.to raise_error
602
+ end
582
603
  end
583
604
 
584
- specify "between" do
585
- lambda{Quantity.new(nil,nil).between? 1.ft,10.m}.should raise_error
605
+ context "when comparing with another nil quantity" do
606
+ specify "greater than" do
607
+ (Quantity.new(nil) > Quantity.new(nil)).should be_false
608
+ end
609
+
610
+ specify "greater than or equals" do
611
+ (Quantity.new(nil) >= Quantity.new(nil)).should be_true
612
+ end
613
+
614
+ specify "less than" do
615
+ (Quantity.new(nil) < Quantity.new(nil)).should be_false
616
+ end
617
+
618
+ specify "less than or equals" do
619
+ (Quantity.new(nil) <= Quantity.new(nil)).should be_true
620
+ end
621
+
622
+ specify "equals" do
623
+ (Quantity.new(nil) == Quantity.new(nil)).should be_true
624
+ end
625
+
626
+ specify "range" do
627
+ (Quantity.new(nil)..Quantity.new(nil)).should eq(Quantity.new(nil,'unity')..Quantity.new(nil, 'unity'))
628
+ end
586
629
  end
630
+
587
631
  end
588
632
 
589
633
  it "should be greater than" do
@@ -650,13 +694,12 @@ describe Quantity do
650
694
  lambda{20.ft === (1.ft..3)}.should raise_error
651
695
  end
652
696
 
653
- specify "a range with nil quantities raises an error" do
654
- lambda{Quantity.new(nil,nil)..Quantity.new(nil,nil)}.should raise_error
655
- lambda{Quantity.new(nil,nil)..20.ft}.should raise_error
697
+ specify "a range with one nil quantity raises an error" do
698
+ lambda{Quantity.new(nil)..20.ft}.should raise_error
656
699
  end
657
700
 
658
701
  specify "cover? with nil quantities raises an error" do
659
- lambda{(2.ft..20.ft).cover?(Quantity.new(nil,nil))}.should raise_error
702
+ lambda{(2.ft..20.ft).cover?(Quantity.new(nil))}.should raise_error
660
703
  end
661
704
 
662
705
  it "should return unit consolidation setting" do
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quantify
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
5
5
  segments:
6
6
  - 3
7
7
  - 2
8
- - 0
8
+ - 1
9
9
  prerelease: false
10
10
  platform: ruby
11
11
  authors:
@@ -18,7 +18,7 @@ default_executable: !!null
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: activesupport
21
- requirement: &24562920 !ruby/object:Gem::Requirement
21
+ requirement: &18752180 !ruby/object:Gem::Requirement
22
22
  none: false
23
23
  requirements:
24
24
  - - ~>
@@ -29,10 +29,10 @@ dependencies:
29
29
  - 0
30
30
  type: :runtime
31
31
  prerelease: false
32
- version_requirements: *24562920
32
+ version_requirements: *18752180
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: i18n
35
- requirement: &24561840 !ruby/object:Gem::Requirement
35
+ requirement: &18751100 !ruby/object:Gem::Requirement
36
36
  none: false
37
37
  requirements:
38
38
  - - ! '>='
@@ -42,10 +42,10 @@ dependencies:
42
42
  - 0
43
43
  type: :runtime
44
44
  prerelease: false
45
- version_requirements: *24561840
45
+ version_requirements: *18751100
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bundler
48
- requirement: &24557200 !ruby/object:Gem::Requirement
48
+ requirement: &18745940 !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  - 0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *24557200
58
+ version_requirements: *18745940
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jeweler
61
- requirement: &24555280 !ruby/object:Gem::Requirement
61
+ requirement: &18744180 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -70,10 +70,10 @@ dependencies:
70
70
  - 4
71
71
  type: :development
72
72
  prerelease: false
73
- version_requirements: *24555280
73
+ version_requirements: *18744180
74
74
  - !ruby/object:Gem::Dependency
75
75
  name: rspec
76
- requirement: &24554180 !ruby/object:Gem::Requirement
76
+ requirement: &18743160 !ruby/object:Gem::Requirement
77
77
  none: false
78
78
  requirements:
79
79
  - - ~>
@@ -85,10 +85,10 @@ dependencies:
85
85
  - 0
86
86
  type: :development
87
87
  prerelease: false
88
- version_requirements: *24554180
88
+ version_requirements: *18743160
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: simplecov
91
- requirement: &24553080 !ruby/object:Gem::Requirement
91
+ requirement: &18742040 !ruby/object:Gem::Requirement
92
92
  none: false
93
93
  requirements:
94
94
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  - 0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *24553080
101
+ version_requirements: *18742040
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rdoc
104
- requirement: &24552260 !ruby/object:Gem::Requirement
104
+ requirement: &18741200 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -111,7 +111,7 @@ dependencies:
111
111
  - 0
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *24552260
114
+ version_requirements: *18741200
115
115
  description: A gem to support physical quantities and unit conversions
116
116
  email: andrew.berkeley.is@googlemail.com
117
117
  executables: []
@@ -168,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  segments:
170
170
  - 0
171
- hash: 4343267713667360298
171
+ hash: -2814138011086079233
172
172
  required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  none: false
174
174
  requirements: