weight_conversion 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/config/locales/en.yml +7 -0
- data/lib/weight_conversion.rb +4 -0
- data/lib/weight_conversion/version.rb +1 -1
- data/spec/weight_conversion_spec.rb +31 -31
- data/weight_conversion-0.1.0.gem +0 -0
- data/weight_conversion.gemspec +2 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd9e7cdddebf35e40424217165533c8da9fc68a1
|
4
|
+
data.tar.gz: 3d65beb19dd1c646a07fe2286fc2b9f27b80d6b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 525663a93d0c6de469b013e296b4d79570d4de62e5f03ea47b5ac68f701899fdcc7ec09da16c820a6b33419e427520804e7547ec6f85f65c15176d3b731bf864
|
7
|
+
data.tar.gz: '0786aa42dfa062d51f5344dde2e305ee2abe43d123bc3340d779b6ea1c27716ca167c4dd46cadd04b66c75f25fe1232868ee0537088dd21a3bc0778b771a9cdd'
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# WeightConversion (0.
|
1
|
+
# WeightConversion (0.2.0)
|
2
2
|
|
3
3
|
* [![Code Climate](https://codeclimate.com/github/pzupan/weight_conversion.png)](https://codeclimate.com/github/pzupan/weight_conversion)
|
4
4
|
* [![Build Status](https://api.travis-ci.org/pzupan/weight_conversion.png)](https://travis-ci.org/pzupan/weight_conversion)
|
data/lib/weight_conversion.rb
CHANGED
@@ -8,66 +8,66 @@ describe Weight do
|
|
8
8
|
let(:one_gm) { Weight.new(1, :gm) }
|
9
9
|
|
10
10
|
it 'should take two options value and unit type' do
|
11
|
-
Weight.new(1, :lb).
|
11
|
+
expect(Weight.new(1, :lb)).to be_instance_of(Weight)
|
12
12
|
end
|
13
13
|
|
14
14
|
describe 'math operators' do
|
15
15
|
it 'for minus operator result unit should be equal to first object unit' do
|
16
|
-
(one_kg - one_lb).unit.
|
16
|
+
expect((one_kg - one_lb).unit).to eq(:kg)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'for plus operator result unit should be equal to first object unit' do
|
20
|
-
(one_kg + one_lb).unit.
|
20
|
+
expect((one_kg + one_lb).unit).to eq(:kg)
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'minus operator should compute weight objects with different units properly' do
|
24
|
-
(one_kg - one_lb).
|
25
|
-
(one_lb - one_oz).
|
24
|
+
expect(one_kg - one_lb).to be > one_lb
|
25
|
+
expect(one_lb - one_oz).to be < one_lb
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'plua operator should compute weight objects with different units properly' do
|
29
|
-
(one_gm + one_oz).
|
30
|
-
(one_oz + one_lb).
|
29
|
+
expect(one_gm + one_oz).to be < one_lb
|
30
|
+
expect(one_oz + one_lb).to be > one_lb
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'plus operator should have proper result' do
|
34
|
-
(one_lb + one_lb).
|
34
|
+
expect(one_lb + one_lb).to eq(Weight.new(2, :lb))
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'two objects with the same weight and type should be equal' do
|
38
|
-
one_kg.
|
38
|
+
expect(one_kg).to eq(Weight.new(1, :kg))
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'operation resulting in zero is okay' do
|
42
|
-
(one_lb - one_lb).
|
42
|
+
expect(one_lb - one_lb).to eq(Weight.new(0, :lb))
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'times operator should have proper result' do
|
46
|
-
(one_lb * 2).
|
46
|
+
expect(one_lb * 2).to eq(Weight.new(2, :lb))
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'operation on something that is not a Weight should raise an error' do
|
50
|
-
expect do
|
50
|
+
expect do
|
51
51
|
(one_lb + 1)
|
52
52
|
end.to raise_error(TypeError)
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'attempting to multiply a weight by another weight should raise an error' do
|
56
|
-
expect do
|
56
|
+
expect do
|
57
57
|
(one_lb * one_lb)
|
58
58
|
end.to raise_error(TypeError)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'multiplication should have proper result' do
|
62
|
-
(one_kg * 2).
|
62
|
+
expect(one_kg * 2).to eq(Weight.new(2, :kg))
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'division should have proper result' do
|
66
|
-
(Weight.new(2, :kg) / 2).
|
66
|
+
expect(Weight.new(2, :kg) / 2).to eq(one_kg)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'attempting to divide a weight by another weight should raise an error' do
|
70
|
-
expect do
|
70
|
+
expect do
|
71
71
|
(one_lb / one_lb)
|
72
72
|
end.to raise_error(TypeError)
|
73
73
|
end
|
@@ -75,35 +75,35 @@ describe Weight do
|
|
75
75
|
|
76
76
|
describe 'calculation between different units' do
|
77
77
|
it 'should convert 1 kg to 2.2046 lbs' do
|
78
|
-
Weight.new(1, :kg).to_lbs.
|
78
|
+
expect(Weight.new(1, :kg).to_lbs).to eq(2.2046)
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'should convert 1 lbs to 0.45359 kg' do
|
82
|
-
Weight.new(1, :lb).to_kgs.
|
82
|
+
expect(Weight.new(1, :lb).to_kgs).to eq(0.4536)
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'should convert 1 kg to 35.2740 ounces' do
|
86
|
-
Weight.new(1, :kg).to_ozs.
|
86
|
+
expect(Weight.new(1, :kg).to_ozs).to eq(35.2740)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'should convert 1 kg to 1000 grams' do
|
90
|
-
Weight.new(1, :kg).to_gms.
|
90
|
+
expect(Weight.new(1, :kg).to_gms).to eq(1000)
|
91
91
|
end
|
92
92
|
|
93
93
|
it 'should convert 1000 gms to 1 kg' do
|
94
|
-
Weight.new(1000, :gm).to_kgs.
|
94
|
+
expect(Weight.new(1000, :gm).to_kgs).to eq(1)
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'should convert 28.3495 gms to 1 oz' do
|
98
|
-
Weight.new(28.3495, :gm).to_ozs.
|
98
|
+
expect(Weight.new(28.3495, :gm).to_ozs).to eq(1)
|
99
99
|
end
|
100
100
|
|
101
101
|
it 'should convert 453.5923 gms to 1 lb' do
|
102
|
-
Weight.new(453.5923, :gm).to_lbs.
|
102
|
+
expect(Weight.new(453.5923, :gm).to_lbs).to eq(1)
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'should convert 0 kgs to 0 lb' do
|
106
|
-
Weight.new(0, 'kg').to_lbs.
|
106
|
+
expect(Weight.new(0, 'kg').to_lbs).to eq(0.0)
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'should raise an error when the weight is negative' do
|
@@ -113,33 +113,33 @@ describe Weight do
|
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'should return the weight in pounds when converted to_f' do
|
116
|
-
Weight.new(0.6, 'lb').to_f.
|
116
|
+
expect(Weight.new(0.6, 'lb').to_f).to eq(0.6)
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'should round 0.6 lbs to 1 lb when converted to_i' do
|
120
|
-
Weight.new(0.6, 'lb').to_i.
|
120
|
+
expect(Weight.new(0.6, 'lb').to_i).to eq(1)
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should round 0.5 lbs to 1 lb when converted to_i' do
|
124
|
-
Weight.new(0.5, 'lb').to_i.
|
124
|
+
expect(Weight.new(0.5, 'lb').to_i).to eq(1)
|
125
125
|
end
|
126
126
|
|
127
127
|
it 'should round 0.4 lbs to 0 lb when converted to_i' do
|
128
|
-
Weight.new(0.4, 'lb').to_i.
|
128
|
+
expect(Weight.new(0.4, 'lb').to_i).to eq(0)
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
132
|
describe 'comparison of different weights' do
|
133
133
|
it 'two pounds should be more than one' do
|
134
|
-
Weight.new(2, :lb).
|
134
|
+
expect(Weight.new(2, :lb)).to be > one_lb
|
135
135
|
end
|
136
136
|
|
137
137
|
it 'two pounds should be greater than or equal to one plus one' do
|
138
|
-
Weight.new(2, :lb) >= one_lb + one_lb
|
138
|
+
expect(Weight.new(2, :lb)).to be >= (one_lb + one_lb)
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'one pound should be less than two' do
|
142
|
-
one_lb.
|
142
|
+
expect(one_lb).to be < Weight.new(2, :lb)
|
143
143
|
end
|
144
144
|
|
145
145
|
it 'attempting to compare a weight to something that is not a weight should raise an error' do
|
Binary file
|
data/weight_conversion.gemspec
CHANGED
@@ -16,9 +16,10 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
19
|
+
spec.require_paths = ["lib", "config"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.7"
|
22
22
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
23
|
spec.add_development_dependency "rspec", "~> 3.4"
|
24
|
+
|
24
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weight_conversion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Zupan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,10 +66,12 @@ files:
|
|
66
66
|
- LICENSE.txt
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
|
+
- config/locales/en.yml
|
69
70
|
- lib/weight_conversion.rb
|
70
71
|
- lib/weight_conversion/version.rb
|
71
72
|
- spec/spec_helper.rb
|
72
73
|
- spec/weight_conversion_spec.rb
|
74
|
+
- weight_conversion-0.1.0.gem
|
73
75
|
- weight_conversion.gemspec
|
74
76
|
homepage: ''
|
75
77
|
licenses:
|
@@ -79,6 +81,7 @@ post_install_message:
|
|
79
81
|
rdoc_options: []
|
80
82
|
require_paths:
|
81
83
|
- lib
|
84
|
+
- config
|
82
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
83
86
|
requirements:
|
84
87
|
- - ">="
|
@@ -91,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
94
|
version: '0'
|
92
95
|
requirements: []
|
93
96
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.6.6
|
95
98
|
signing_key:
|
96
99
|
specification_version: 4
|
97
100
|
summary: Gem to convert measures of weight.
|