bmicalc 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b54dd21218de2e8062ae2318c58c6cf2038f296
4
- data.tar.gz: c658de88014e818dfd3dc52e0b34adc4bc52ae1b
3
+ metadata.gz: caddc3d9ae32bd5dbc245aaf0ce951f436f5b6e5
4
+ data.tar.gz: 2ca53c881e67210ee7167012fa02aa0fcab38877
5
5
  SHA512:
6
- metadata.gz: ba19def99612fd9bfcb1b932a4194351b301b2310473a90dbf9d864f2423d10375364b03af64bdbb84e7c3172caf27cb62967eaa66b58b4d99469c272e7b7aaf
7
- data.tar.gz: 88c81c056436cbc273d6a262a5e797704e4905773761e1640259d22c3d0ab1c2553ef52b14243046122e7fa1ff5a35087d506f1887e947283e7417e8bfcec4f7
6
+ metadata.gz: e10b639bd9f98a46ddd4240c7647c97fb74cb9f26ed9e424efa3b1d28daa6bc3034a28187b64b031b495e7b793909dbb5e15a6195bb98767490116bae51d8015
7
+ data.tar.gz: a3f7cbb9e7d0b3454a55d612ae0678e2d351a0d3c6ba23f6ac25ada822dd5d4fa536e7ef317339601dd5d2f91262029e2970989c8e6fbd79424b3c9b26114c37
@@ -6,9 +6,10 @@ class Bmicalc
6
6
 
7
7
  def initialize(options = {})
8
8
  @round = options.fetch(:round, true)
9
+ @metric = options.fetch(:metric, true)
9
10
  end
10
11
 
11
- def result(options = {})
12
+ def result
12
13
  error unless weight && height
13
14
  calculate_result
14
15
  end
@@ -16,10 +17,26 @@ class Bmicalc
16
17
  private
17
18
 
18
19
  def calculate_result
20
+ if @metric
21
+ round(metric)
22
+ else
23
+ round(imperial)
24
+ end
25
+ end
26
+
27
+ def metric
28
+ weight / (height * height)
29
+ end
30
+
31
+ def imperial
32
+ (weight * 703) / (height * height)
33
+ end
34
+
35
+ def round(result)
19
36
  if @round
20
- (weight / (height * height)).round
37
+ result.round
21
38
  else
22
- weight / (height * height)
39
+ result
23
40
  end
24
41
  end
25
42
 
@@ -1,3 +1,3 @@
1
1
  class Bmicalc
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,48 +2,65 @@ require 'bmicalc'
2
2
 
3
3
  describe Bmicalc do
4
4
 
5
- context 'returns bmi' do
5
+ context 'metric' do
6
+ context 'returns bmi' do
6
7
 
7
- it 'underweight' do
8
- subject.weight = 54
9
- subject.height = 1.78
10
- expect(subject.result).to eq(17)
8
+ it 'underweight' do
9
+ subject.weight = 54
10
+ subject.height = 1.78
11
+ expect(subject.result).to eq(17)
12
+ end
13
+
14
+ it 'ideal' do
15
+ subject.weight = 64
16
+ subject.height = 1.78
17
+ expect(subject.result).to eq(20)
18
+ end
19
+
20
+ it 'overweight' do
21
+ subject.weight = 68
22
+ subject.height = 1.48
23
+ expect(subject.result).to eq(31)
24
+ end
25
+
26
+ it 'obese' do
27
+ subject.weight = 118
28
+ subject.height = 1.68
29
+ expect(subject.result).to eq(42)
30
+ end
11
31
  end
12
32
 
13
- it 'ideal' do
14
- subject.weight = 64
33
+ it 'returns correct error message for weight' do
15
34
  subject.height = 1.78
16
- expect(subject.result).to eq(20)
35
+ proc { subject.result }.should raise_error(StandardError, 'weight not set')
17
36
  end
18
37
 
19
- it 'overweight' do
20
- subject.weight = 68
21
- subject.height = 1.48
22
- expect(subject.result).to eq(31)
38
+ it 'returns correct error message for height' do
39
+ subject.weight = 64
40
+ proc { subject.result }.should raise_error(StandardError, 'height not set')
23
41
  end
24
42
 
25
- it 'obese' do
26
- subject.weight = 118
27
- subject.height = 1.68
28
- expect(subject.result).to eq(42)
43
+ it 'returns bmi without rounding' do
44
+ bmi = Bmicalc.new(round: false)
45
+ bmi.weight = 64
46
+ bmi.height = 1.78
47
+ expect(bmi.result).to eq(20.199469763918696)
29
48
  end
30
49
  end
31
50
 
32
- it 'returns correct error message for weight' do
33
- subject.height = 1.78
34
- proc { subject.result }.should raise_error(StandardError, 'weight not set')
35
- end
36
-
37
- it 'returns correct error message for height' do
38
- subject.weight = 64
39
- proc { subject.result }.should raise_error(StandardError, 'height not set')
40
- end
51
+ context 'imperial' do
52
+ it 'calculates with imperial values' do
53
+ bmi = Bmicalc.new(metric: false)
54
+ bmi.weight = 141
55
+ bmi.height = 70
56
+ expect(bmi.result).to eq(20)
57
+ end
41
58
 
42
- it 'returns bmi without rounding' do
43
- bmi = Bmicalc.new(round: false)
44
- bmi.weight = 64
45
- bmi.height = 1.78
46
- expect(bmi.result).to eq(20.199469763918696)
59
+ it 'returns bmi without rounding' do
60
+ bmi = Bmicalc.new(metric: false, round: false)
61
+ bmi.weight = 141
62
+ bmi.height = 70.1
63
+ expect(bmi.result).to eq(20.171509622487545)
64
+ end
47
65
  end
48
-
49
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmicalc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Kadwill