ruby-measurement 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/CI.yml +30 -0
  3. data/CHANGELOG.md +25 -10
  4. data/README.md +13 -7
  5. data/lib/ruby-measurement/core_ext/string.rb +2 -2
  6. data/lib/ruby-measurement/core_ext/symbol.rb +1 -1
  7. data/lib/ruby-measurement/measurement.rb +101 -42
  8. data/lib/ruby-measurement/unit.rb +34 -28
  9. data/lib/ruby-measurement/version.rb +1 -1
  10. data/ruby-measurement.gemspec +5 -4
  11. data/spec/ruby-measurement/core_ext/numeric_spec.rb +2 -2
  12. data/spec/ruby-measurement/core_ext/string_spec.rb +12 -12
  13. data/spec/ruby-measurement/core_ext/symbol_spec.rb +3 -3
  14. data/spec/ruby-measurement/definitions/metric/area_spec.rb +32 -32
  15. data/spec/ruby-measurement/definitions/metric/capacity_spec.rb +18 -18
  16. data/spec/ruby-measurement/definitions/metric/length_spec.rb +128 -128
  17. data/spec/ruby-measurement/definitions/metric/volume_spec.rb +128 -128
  18. data/spec/ruby-measurement/definitions/metric/weight_spec.rb +160 -160
  19. data/spec/ruby-measurement/definitions/us_customary/area_spec.rb +72 -72
  20. data/spec/ruby-measurement/definitions/us_customary/capacity_spec.rb +32 -32
  21. data/spec/ruby-measurement/definitions/us_customary/length_spec.rb +128 -128
  22. data/spec/ruby-measurement/definitions/us_customary/volume_spec.rb +98 -98
  23. data/spec/ruby-measurement/definitions/us_customary/weight_spec.rb +72 -72
  24. data/spec/ruby-measurement/measurement_spec.rb +238 -164
  25. data/spec/ruby-measurement/unit_builder_spec.rb +35 -35
  26. data/spec/ruby-measurement/unit_spec.rb +84 -41
  27. data/tasks/rspec.rake +1 -1
  28. metadata +29 -25
  29. data/.travis.yml +0 -4
@@ -2,200 +2,200 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Measurement do
5
+ RSpec.describe Measurement do
6
6
  describe 'gallons' do
7
- subject { Measurement.parse('1 gal') }
8
-
7
+ subject { described_class.parse('1 gal') }
8
+
9
9
  it 'converts to quarts' do
10
- subject.convert_to(:qt).quantity.should eq 4
10
+ expect(subject.convert_to(:qt).quantity).to eq 4
11
11
  end
12
-
12
+
13
13
  it 'converts to pints' do
14
- subject.convert_to(:pt).quantity.should eq 8
14
+ expect(subject.convert_to(:pt).quantity).to eq 8
15
15
  end
16
-
16
+
17
17
  it 'converts to cups' do
18
- subject.convert_to(:c).quantity.should eq 16
18
+ expect(subject.convert_to(:c).quantity).to eq 16
19
19
  end
20
-
20
+
21
21
  it 'converts to fluid ounces' do
22
- subject.convert_to(:'fl oz').quantity.should eq 128
22
+ expect(subject.convert_to(:'fl oz').quantity).to eq 128
23
23
  end
24
-
24
+
25
25
  it 'converts to tablespoons' do
26
- subject.convert_to(:tbsp).quantity.should eq 256
26
+ expect(subject.convert_to(:tbsp).quantity).to eq 256
27
27
  end
28
-
28
+
29
29
  it 'converts to teaspoons' do
30
- subject.convert_to(:tsp).quantity.should eq 768
30
+ expect(subject.convert_to(:tsp).quantity).to eq 768
31
31
  end
32
32
  end
33
-
33
+
34
34
  describe 'quarts' do
35
- subject { Measurement.parse('4 qt') }
36
-
35
+ subject { described_class.parse('4 qt') }
36
+
37
37
  it 'converts to gallons' do
38
- subject.convert_to(:gal).quantity.should eq 1
38
+ expect(subject.convert_to(:gal).quantity).to eq 1
39
39
  end
40
-
40
+
41
41
  it 'converts to pints' do
42
- subject.convert_to(:pt).quantity.should eq 8
42
+ expect(subject.convert_to(:pt).quantity).to eq 8
43
43
  end
44
-
44
+
45
45
  it 'converts to cups' do
46
- subject.convert_to(:c).quantity.should eq 16
46
+ expect(subject.convert_to(:c).quantity).to eq 16
47
47
  end
48
-
48
+
49
49
  it 'converts to fluid ounces' do
50
- subject.convert_to(:'fl oz').quantity.should eq 128
50
+ expect(subject.convert_to(:'fl oz').quantity).to eq 128
51
51
  end
52
-
52
+
53
53
  it 'converts to tablespoons' do
54
- subject.convert_to(:tbsp).quantity.should eq 256
54
+ expect(subject.convert_to(:tbsp).quantity).to eq 256
55
55
  end
56
-
56
+
57
57
  it 'converts to teaspoons' do
58
- subject.convert_to(:tsp).quantity.should eq 768
58
+ expect(subject.convert_to(:tsp).quantity).to eq 768
59
59
  end
60
60
  end
61
-
61
+
62
62
  describe 'pints' do
63
- subject { Measurement.parse('8 pt') }
64
-
63
+ subject { described_class.parse('8 pt') }
64
+
65
65
  it 'converts to gallons' do
66
- subject.convert_to(:gal).quantity.should eq 1
66
+ expect(subject.convert_to(:gal).quantity).to eq 1
67
67
  end
68
-
68
+
69
69
  it 'converts to quarts' do
70
- subject.convert_to(:qt).quantity.should eq 4
70
+ expect(subject.convert_to(:qt).quantity).to eq 4
71
71
  end
72
-
72
+
73
73
  it 'converts to cups' do
74
- subject.convert_to(:c).quantity.should eq 16
74
+ expect(subject.convert_to(:c).quantity).to eq 16
75
75
  end
76
-
76
+
77
77
  it 'converts to fluid ounces' do
78
- subject.convert_to(:'fl oz').quantity.should eq 128
78
+ expect(subject.convert_to(:'fl oz').quantity).to eq 128
79
79
  end
80
-
80
+
81
81
  it 'converts to tablespoons' do
82
- subject.convert_to(:tbsp).quantity.should eq 256
82
+ expect(subject.convert_to(:tbsp).quantity).to eq 256
83
83
  end
84
-
84
+
85
85
  it 'converts to teaspoons' do
86
- subject.convert_to(:tsp).quantity.should eq 768
86
+ expect(subject.convert_to(:tsp).quantity).to eq 768
87
87
  end
88
88
  end
89
-
89
+
90
90
  describe 'cups' do
91
- subject { Measurement.parse('16 c') }
92
-
91
+ subject { described_class.parse('16 c') }
92
+
93
93
  it 'converts to gallons' do
94
- subject.convert_to(:gal).quantity.should eq 1
94
+ expect(subject.convert_to(:gal).quantity).to eq 1
95
95
  end
96
-
96
+
97
97
  it 'converts to quarts' do
98
- subject.convert_to(:qt).quantity.should eq 4
98
+ expect(subject.convert_to(:qt).quantity).to eq 4
99
99
  end
100
-
100
+
101
101
  it 'converts to pints' do
102
- subject.convert_to(:pt).quantity.should eq 8
102
+ expect(subject.convert_to(:pt).quantity).to eq 8
103
103
  end
104
-
104
+
105
105
  it 'converts to fluid ounces' do
106
- subject.convert_to(:'fl oz').quantity.should eq 128
106
+ expect(subject.convert_to(:'fl oz').quantity).to eq 128
107
107
  end
108
-
108
+
109
109
  it 'converts to tablespoons' do
110
- subject.convert_to(:tbsp).quantity.should eq 256
110
+ expect(subject.convert_to(:tbsp).quantity).to eq 256
111
111
  end
112
-
112
+
113
113
  it 'converts to teaspoons' do
114
- subject.convert_to(:tsp).quantity.should eq 768
114
+ expect(subject.convert_to(:tsp).quantity).to eq 768
115
115
  end
116
116
  end
117
-
117
+
118
118
  describe 'fluid ounces' do
119
- subject { Measurement.parse('128 fl oz') }
120
-
119
+ subject { described_class.parse('128 fl oz') }
120
+
121
121
  it 'converts to gallons' do
122
- subject.convert_to(:gal).quantity.should eq 1
122
+ expect(subject.convert_to(:gal).quantity).to eq 1
123
123
  end
124
-
124
+
125
125
  it 'converts to quarts' do
126
- subject.convert_to(:qt).quantity.should eq 4
126
+ expect(subject.convert_to(:qt).quantity).to eq 4
127
127
  end
128
-
128
+
129
129
  it 'converts to pints' do
130
- subject.convert_to(:pt).quantity.should eq 8
130
+ expect(subject.convert_to(:pt).quantity).to eq 8
131
131
  end
132
-
132
+
133
133
  it 'converts to cups' do
134
- subject.convert_to(:c).quantity.should eq 16
134
+ expect(subject.convert_to(:c).quantity).to eq 16
135
135
  end
136
-
136
+
137
137
  it 'converts to tablespoons' do
138
- subject.convert_to(:tbsp).quantity.should eq 256
138
+ expect(subject.convert_to(:tbsp).quantity).to eq 256
139
139
  end
140
-
140
+
141
141
  it 'converts to teaspoons' do
142
- subject.convert_to(:tsp).quantity.should eq 768
142
+ expect(subject.convert_to(:tsp).quantity).to eq 768
143
143
  end
144
144
  end
145
-
145
+
146
146
  describe 'tablespoons' do
147
- subject { Measurement.parse('256 tbsp') }
148
-
147
+ subject { described_class.parse('256 tbsp') }
148
+
149
149
  it 'converts to gallons' do
150
- subject.convert_to(:gal).quantity.should eq 1
150
+ expect(subject.convert_to(:gal).quantity).to eq 1
151
151
  end
152
-
152
+
153
153
  it 'converts to quarts' do
154
- subject.convert_to(:qt).quantity.should eq 4
154
+ expect(subject.convert_to(:qt).quantity).to eq 4
155
155
  end
156
-
156
+
157
157
  it 'converts to pints' do
158
- subject.convert_to(:pt).quantity.should eq 8
158
+ expect(subject.convert_to(:pt).quantity).to eq 8
159
159
  end
160
-
160
+
161
161
  it 'converts to cups' do
162
- subject.convert_to(:c).quantity.should eq 16
162
+ expect(subject.convert_to(:c).quantity).to eq 16
163
163
  end
164
-
164
+
165
165
  it 'converts to fluid ounces' do
166
- subject.convert_to(:'fl oz').quantity.should eq 128
166
+ expect(subject.convert_to(:'fl oz').quantity).to eq 128
167
167
  end
168
-
168
+
169
169
  it 'converts to teaspoons' do
170
- subject.convert_to(:tsp).quantity.should eq 768
170
+ expect(subject.convert_to(:tsp).quantity).to eq 768
171
171
  end
172
172
  end
173
-
173
+
174
174
  describe 'teaspoons' do
175
- subject { Measurement.parse('768 tsp') }
176
-
175
+ subject { described_class.parse('768 tsp') }
176
+
177
177
  it 'converts to gallons' do
178
- subject.convert_to(:gal).quantity.should eq 1
178
+ expect(subject.convert_to(:gal).quantity).to eq 1
179
179
  end
180
-
180
+
181
181
  it 'converts to quarts' do
182
- subject.convert_to(:qt).quantity.should eq 4
182
+ expect(subject.convert_to(:qt).quantity).to eq 4
183
183
  end
184
-
184
+
185
185
  it 'converts to pints' do
186
- subject.convert_to(:pt).quantity.should eq 8
186
+ expect(subject.convert_to(:pt).quantity).to eq 8
187
187
  end
188
-
188
+
189
189
  it 'converts to cups' do
190
- subject.convert_to(:c).quantity.should eq 16
190
+ expect(subject.convert_to(:c).quantity).to eq 16
191
191
  end
192
-
192
+
193
193
  it 'converts to fluid ounces' do
194
- subject.convert_to(:'fl oz').quantity.should eq 128
194
+ expect(subject.convert_to(:'fl oz').quantity).to eq 128
195
195
  end
196
-
196
+
197
197
  it 'converts to tablespoons' do
198
- subject.convert_to(:tbsp).quantity.should eq 256
198
+ expect(subject.convert_to(:tbsp).quantity).to eq 256
199
199
  end
200
200
  end
201
201
  end
@@ -2,148 +2,148 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Measurement do
5
+ RSpec.describe Measurement do
6
6
  describe 'tons' do
7
- subject { Measurement.parse('1 ton') }
8
-
7
+ subject { described_class.parse('1 ton') }
8
+
9
9
  it 'converts to hundredweights' do
10
- subject.convert_to(:cwt).quantity.should eq 20
10
+ expect(subject.convert_to(:cwt).quantity).to eq 20
11
11
  end
12
-
12
+
13
13
  it 'converts to pounds' do
14
- subject.convert_to(:lbs).quantity.should eq 2_000
14
+ expect(subject.convert_to(:lbs).quantity).to eq 2_000
15
15
  end
16
-
16
+
17
17
  it 'converts to ounces' do
18
- subject.convert_to(:oz).quantity.should eq 32_000
18
+ expect(subject.convert_to(:oz).quantity).to eq 32_000
19
19
  end
20
-
20
+
21
21
  it 'converts to drams' do
22
- subject.convert_to(:dr).quantity.should eq 512_000
22
+ expect(subject.convert_to(:dr).quantity).to eq 512_000
23
23
  end
24
-
24
+
25
25
  it 'converts to grains' do
26
- subject.convert_to(:gr).quantity.should eq 14_000_000
26
+ expect(subject.convert_to(:gr).quantity).to eq 14_000_000
27
27
  end
28
28
  end
29
-
29
+
30
30
  describe 'hundredweights' do
31
- subject { Measurement.parse('20 cwt') }
32
-
31
+ subject { described_class.parse('20 cwt') }
32
+
33
33
  it 'converts to tons' do
34
- subject.convert_to(:ton).quantity.should eq 1
34
+ expect(subject.convert_to(:ton).quantity).to eq 1
35
35
  end
36
-
36
+
37
37
  it 'converts to pounds' do
38
- subject.convert_to(:lbs).quantity.should eq 2_000
38
+ expect(subject.convert_to(:lbs).quantity).to eq 2_000
39
39
  end
40
-
40
+
41
41
  it 'converts to ounces' do
42
- subject.convert_to(:oz).quantity.should eq 32_000
42
+ expect(subject.convert_to(:oz).quantity).to eq 32_000
43
43
  end
44
-
44
+
45
45
  it 'converts to drams' do
46
- subject.convert_to(:dr).quantity.should eq 512_000
46
+ expect(subject.convert_to(:dr).quantity).to eq 512_000
47
47
  end
48
-
48
+
49
49
  it 'converts to grains' do
50
- subject.convert_to(:gr).quantity.should eq 14_000_000
50
+ expect(subject.convert_to(:gr).quantity).to eq 14_000_000
51
51
  end
52
52
  end
53
-
53
+
54
54
  describe 'pounds' do
55
- subject { Measurement.parse('2000 lbs') }
56
-
55
+ subject { described_class.parse('2000 lbs') }
56
+
57
57
  it 'converts to tons' do
58
- subject.convert_to(:ton).quantity.should eq 1
58
+ expect(subject.convert_to(:ton).quantity).to eq 1
59
59
  end
60
-
60
+
61
61
  it 'converts to hundredweights' do
62
- subject.convert_to(:cwt).quantity.should eq 20
62
+ expect(subject.convert_to(:cwt).quantity).to eq 20
63
63
  end
64
-
64
+
65
65
  it 'converts to ounces' do
66
- subject.convert_to(:oz).quantity.should eq 32_000
66
+ expect(subject.convert_to(:oz).quantity).to eq 32_000
67
67
  end
68
-
68
+
69
69
  it 'converts to drams' do
70
- subject.convert_to(:dr).quantity.should eq 512_000
70
+ expect(subject.convert_to(:dr).quantity).to eq 512_000
71
71
  end
72
-
72
+
73
73
  it 'converts to grains' do
74
- subject.convert_to(:gr).quantity.should eq 14_000_000
74
+ expect(subject.convert_to(:gr).quantity).to eq 14_000_000
75
75
  end
76
76
  end
77
-
77
+
78
78
  describe 'ounces' do
79
- subject { Measurement.parse('32000 oz') }
80
-
79
+ subject { described_class.parse('32000 oz') }
80
+
81
81
  it 'converts to tons' do
82
- subject.convert_to(:ton).quantity.should eq 1
82
+ expect(subject.convert_to(:ton).quantity).to eq 1
83
83
  end
84
-
84
+
85
85
  it 'converts to hundredweights' do
86
- subject.convert_to(:cwt).quantity.should eq 20
86
+ expect(subject.convert_to(:cwt).quantity).to eq 20
87
87
  end
88
-
88
+
89
89
  it 'converts to pounds' do
90
- subject.convert_to(:lbs).quantity.should eq 2_000
90
+ expect(subject.convert_to(:lbs).quantity).to eq 2_000
91
91
  end
92
-
92
+
93
93
  it 'converts to drams' do
94
- subject.convert_to(:dr).quantity.should eq 512_000
94
+ expect(subject.convert_to(:dr).quantity).to eq 512_000
95
95
  end
96
-
96
+
97
97
  it 'converts to grains' do
98
- subject.convert_to(:gr).quantity.should eq 14_000_000
98
+ expect(subject.convert_to(:gr).quantity).to eq 14_000_000
99
99
  end
100
100
  end
101
-
101
+
102
102
  describe 'drams' do
103
- subject { Measurement.parse('512000 dr') }
104
-
103
+ subject { described_class.parse('512000 dr') }
104
+
105
105
  it 'converts to tons' do
106
- subject.convert_to(:ton).quantity.should eq 1
106
+ expect(subject.convert_to(:ton).quantity).to eq 1
107
107
  end
108
-
108
+
109
109
  it 'converts to hundredweights' do
110
- subject.convert_to(:cwt).quantity.should eq 20
110
+ expect(subject.convert_to(:cwt).quantity).to eq 20
111
111
  end
112
-
112
+
113
113
  it 'converts to pounds' do
114
- subject.convert_to(:lbs).quantity.should eq 2_000
114
+ expect(subject.convert_to(:lbs).quantity).to eq 2_000
115
115
  end
116
-
116
+
117
117
  it 'converts to ounces' do
118
- subject.convert_to(:oz).quantity.should eq 32_000
118
+ expect(subject.convert_to(:oz).quantity).to eq 32_000
119
119
  end
120
-
120
+
121
121
  it 'converts to grains' do
122
- subject.convert_to(:gr).quantity.should eq 14_000_000
122
+ expect(subject.convert_to(:gr).quantity).to eq 14_000_000
123
123
  end
124
124
  end
125
-
125
+
126
126
  describe 'grains' do
127
- subject { Measurement.parse('14000000 gr') }
128
-
127
+ subject { described_class.parse('14000000 gr') }
128
+
129
129
  it 'converts to tons' do
130
- subject.convert_to(:ton).quantity.should eq 1
130
+ expect(subject.convert_to(:ton).quantity).to eq 1
131
131
  end
132
-
132
+
133
133
  it 'converts to hundredweights' do
134
- subject.convert_to(:cwt).quantity.should eq 20
134
+ expect(subject.convert_to(:cwt).quantity).to eq 20
135
135
  end
136
-
136
+
137
137
  it 'converts to pounds' do
138
- subject.convert_to(:lbs).quantity.should eq 2_000
138
+ expect(subject.convert_to(:lbs).quantity).to eq 2_000
139
139
  end
140
-
140
+
141
141
  it 'converts to ounces' do
142
- subject.convert_to(:oz).quantity.should eq 32_000
142
+ expect(subject.convert_to(:oz).quantity).to eq 32_000
143
143
  end
144
-
144
+
145
145
  it 'converts to drams' do
146
- subject.convert_to(:dr).quantity.should eq 512_000
146
+ expect(subject.convert_to(:dr).quantity).to eq 512_000
147
147
  end
148
148
  end
149
149
  end