bmi 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -0
- data/README.rdoc +42 -10
- data/bin/bmi +43 -5
- data/lib/bmi.rb +2 -152
- data/lib/bmi/bmi.rb +189 -0
- data/lib/bmi/cli.rb +17 -3
- data/test/test_bmi.rb +64 -22
- data/test/test_bmi_cli.rb +23 -23
- metadata +5 -4
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -14,6 +14,8 @@ Write in your comand line 'bmi -w (YourWeight) -b (Your height)' to calculate yo
|
|
14
14
|
|
15
15
|
Body Mass Index
|
16
16
|
|
17
|
+
--------------------
|
18
|
+
|
17
19
|
Imperial BMI Formula
|
18
20
|
|
19
21
|
Bash
|
@@ -24,19 +26,35 @@ Bash
|
|
24
26
|
You are 9% over your ideal weight
|
25
27
|
Overweight
|
26
28
|
|
27
|
-
|
29
|
+
Ruby
|
28
30
|
|
29
31
|
require 'bmi'
|
30
32
|
bmi = BMI.new
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
bmi.calc(data)
|
33
|
+
bmi.weight(189.597,'p') #Note: bmi.weight(189.597) will be in kilograms
|
34
|
+
bmi.height(69.6850,'i') #Note: bmi.height(69.6850) will be on meters
|
35
|
+
bmi.calc
|
35
36
|
|
36
37
|
Your body mass index is: 27
|
37
38
|
You are 9% over your ideal weight
|
38
39
|
Overweight
|
39
40
|
|
41
|
+
Methods
|
42
|
+
|
43
|
+
determinates
|
44
|
+
bmi.determinates # =>"Imperial"
|
45
|
+
get_imperial
|
46
|
+
bmi.get_imperial # => 27.447840253722447
|
47
|
+
get_prime
|
48
|
+
bmi.get_prime # => "9% over your ideal weight"
|
49
|
+
cases
|
50
|
+
bmi.cases # => "Overweight"
|
51
|
+
error
|
52
|
+
bmi.error # => false
|
53
|
+
get_errors
|
54
|
+
bmi.get_errors # => nil
|
55
|
+
|
56
|
+
|
57
|
+
---------------------------
|
40
58
|
|
41
59
|
Metric Imperial BMI Formula
|
42
60
|
|
@@ -48,19 +66,33 @@ Bash
|
|
48
66
|
You are 9% over your ideal weight
|
49
67
|
Overweight
|
50
68
|
|
51
|
-
|
69
|
+
Ruby
|
52
70
|
|
53
71
|
require 'bmi'
|
54
72
|
bmi = BMI.new
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
bmi.calc(data)
|
73
|
+
bmi.weight(86) # or bmi.weight(86,'k')
|
74
|
+
bmi.height(1.77) # or bmi.height(1.77,'m')
|
75
|
+
bmi.calc
|
59
76
|
|
60
77
|
Your body mass index is: 27
|
61
78
|
You are 9% over your ideal weight
|
62
79
|
Overweight
|
63
80
|
|
81
|
+
Methods
|
82
|
+
|
83
|
+
determinates
|
84
|
+
bmi.determinates # =>"Metric"
|
85
|
+
get_imperial
|
86
|
+
bmi.get_metric # => 27.450604870886398
|
87
|
+
get_prime
|
88
|
+
bmi.get_prime # => "9% over your ideal weight"
|
89
|
+
cases
|
90
|
+
bmi.cases # => "Overweight"
|
91
|
+
error
|
92
|
+
bmi.error # => false
|
93
|
+
get_errors
|
94
|
+
bmi.get_errors # => nil
|
95
|
+
|
64
96
|
== REQUIREMENTS:
|
65
97
|
|
66
98
|
Requires ~> ruby-1.9.2-p290
|
data/bin/bmi
CHANGED
@@ -8,6 +8,22 @@ require File.expand_path(File.dirname(__FILE__) + "/../lib/bmi")
|
|
8
8
|
require "bmi/cli"
|
9
9
|
|
10
10
|
data = Bmi::CLI.calc(ARGV)
|
11
|
+
error = false
|
12
|
+
|
13
|
+
errors = {
|
14
|
+
:Exists => false,
|
15
|
+
:Missing => "Error: You must put a weight and a height !",
|
16
|
+
:Mismatch => "Error: Arguments must be Numbers !",
|
17
|
+
:Amount => "Error: Two diferent arguments expected"
|
18
|
+
}
|
19
|
+
|
20
|
+
data.values.each do|v|
|
21
|
+
if (v.class != Fixnum) && (v.to_f == 0)
|
22
|
+
puts errors[:Mismatch]
|
23
|
+
errors[:Exists] = true
|
24
|
+
break
|
25
|
+
end
|
26
|
+
end
|
11
27
|
|
12
28
|
data.select!{ |k, v| v.to_f > 0 }
|
13
29
|
|
@@ -23,14 +39,36 @@ height = data[:height_m] || data[:height_i]
|
|
23
39
|
weight = weight.to_f
|
24
40
|
height = height.to_f
|
25
41
|
|
26
|
-
if imperial
|
27
|
-
bmi =( ( weight ) / ( height * height ) ) * 703
|
28
|
-
end
|
29
42
|
|
30
|
-
if
|
31
|
-
|
43
|
+
if (data.keys.count == 2)
|
44
|
+
if (data[:weight_k] && data[:weight_p]) || (data[:height_m] && data[:height_i])
|
45
|
+
errors[:Exists] = true
|
46
|
+
puts errors[:Missing]
|
47
|
+
end
|
48
|
+
else
|
49
|
+
errors[:Exists] = true
|
50
|
+
puts errors[:Amount]
|
32
51
|
end
|
33
52
|
|
53
|
+
unless errors[:Exists]
|
54
|
+
if imperial == metric
|
55
|
+
if data[:weight_k]
|
56
|
+
height*=0.0254
|
57
|
+
metric=true
|
58
|
+
end
|
59
|
+
if data[:weight_p]
|
60
|
+
height*=39.3700787
|
61
|
+
imperial=true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
if imperial
|
65
|
+
bmi =( ( weight ) / ( height * height ) ) * 703
|
66
|
+
end
|
67
|
+
if metric
|
68
|
+
bmi =( weight ) / ( height * height )
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
34
72
|
if bmi
|
35
73
|
prime = ( bmi / 25 )
|
36
74
|
puts "Your body mass index is: #{bmi.round}"
|
data/lib/bmi.rb
CHANGED
@@ -1,157 +1,7 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
4
3
|
require 'rubygems'
|
5
4
|
require 'optparse'
|
5
|
+
require 'bmi/bmi'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
attr_accessor :data, :metric, :imperial, :bmi, :metric, :percent
|
10
|
-
|
11
|
-
def initialize(data={})
|
12
|
-
@data = data
|
13
|
-
@data = {
|
14
|
-
:weight_k => 0,
|
15
|
-
:height_m => 0,
|
16
|
-
:weight_p => 0,
|
17
|
-
:height_i => 0
|
18
|
-
}
|
19
|
-
@imperial = false
|
20
|
-
@metric = false
|
21
|
-
@weight = 0
|
22
|
-
@height = 0
|
23
|
-
@bmi = 0
|
24
|
-
@prime = 0
|
25
|
-
@percent = 0
|
26
|
-
end
|
27
|
-
|
28
|
-
def loadata(arguments=[])
|
29
|
-
mandatory_options = %w( )
|
30
|
-
|
31
|
-
parser = OptionParser.new do |opts|
|
32
|
-
opts.banner = <<-BANNER.gsub(/^ /,'')
|
33
|
-
Body Mass Index [BMI] help guide
|
34
|
-
|
35
|
-
Usage: #{File.basename($0)} [options]
|
36
|
-
|
37
|
-
Options are:
|
38
|
-
BANNER
|
39
|
-
opts.separator ""
|
40
|
-
|
41
|
-
opts.on("-w", "--weight KILOGRAMS", String,
|
42
|
-
"Your current weight.",
|
43
|
-
"Pleace introduce your weight in kilograms.",
|
44
|
-
"Default: ~") { |arg| @data[:weight_k] = arg }
|
45
|
-
|
46
|
-
|
47
|
-
opts.on("-b", "--height METERS", String,
|
48
|
-
"How hight you are.",
|
49
|
-
"Pleace introduce your height in meters.",
|
50
|
-
"Default: ~") { |arg| @data[:height_m] = arg }
|
51
|
-
|
52
|
-
opts.on("-W", "--Weight POUNDS", String,
|
53
|
-
"Your current weight.",
|
54
|
-
"Pleace introduce your weight in pounds.",
|
55
|
-
"Default: ~") { |arg| @data[:weight_p] = arg }
|
56
|
-
|
57
|
-
opts.on("-B", "--Height INCHES", String,
|
58
|
-
"How hight you are.",
|
59
|
-
"Pleace introduce your height in inches.",
|
60
|
-
"Default: ~") { |arg| @data[:height_i] = arg }
|
61
|
-
|
62
|
-
opts.on("-h", "--help",
|
63
|
-
"Show this help message.") { puts opts}
|
64
|
-
|
65
|
-
opts.parse!(arguments)
|
66
|
-
|
67
|
-
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
68
|
-
puts opts
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def determinates
|
75
|
-
@data.select!{|k,v| v.to_f > 0}
|
76
|
-
@imperial = true if @data[:weight_p] && @data[:height_i]
|
77
|
-
@metric = true if @data[:weight_k] && @data[:height_m]
|
78
|
-
@weight = @data[:weight_k] || @data[:weight_p]
|
79
|
-
@height = @data[:height_m] || @data[:height_i]
|
80
|
-
@weight = @weight.to_f
|
81
|
-
@height = @height.to_f
|
82
|
-
end
|
83
|
-
|
84
|
-
def get_imperial
|
85
|
-
@bmi =( ( @weight ) / ( @height * @height ) ) * 703
|
86
|
-
end
|
87
|
-
|
88
|
-
def get_metric
|
89
|
-
@bmi =( @weight ) / ( @height * @height )
|
90
|
-
end
|
91
|
-
|
92
|
-
def get_prime
|
93
|
-
|
94
|
-
@prime = ( @bmi / 25 )
|
95
|
-
puts "Your body mass index is: #{@bmi.round}"
|
96
|
-
prti = @prime.to_s.match(/\d+/)
|
97
|
-
ceros = @prime.to_s.match(/\.(0+)/)
|
98
|
-
|
99
|
-
|
100
|
-
if !ceros
|
101
|
-
ceros = []
|
102
|
-
ceros[1] = "0"
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
prcnt = @prime.to_s.match(/\.(\d{1,2})/)
|
107
|
-
if prti[0].to_i <= 0
|
108
|
-
@percent = (100)*(ceros[1].length) - (prcnt[1].to_i)
|
109
|
-
puts "You are #{@percent}% under your ideal weight"
|
110
|
-
else
|
111
|
-
@percent = prcnt[1].to_i + (100*(prti[0].to_i-1))
|
112
|
-
puts "You are #{@percent}% over your ideal weight"
|
113
|
-
end
|
114
|
-
return @percent.to_s+"%"
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
def cases
|
119
|
-
case
|
120
|
-
when @bmi < 18.5
|
121
|
-
msj= "Underweight"
|
122
|
-
when @bmi.between?(18.5,25)
|
123
|
-
msj= "Normal"
|
124
|
-
when @bmi.between?(25,30)
|
125
|
-
msj= "Overweight"
|
126
|
-
when @bmi.between?(30,35)
|
127
|
-
msj= "Obese Class I"
|
128
|
-
when @bmi.between?(35,40)
|
129
|
-
msj= "Obese Class II"
|
130
|
-
when @bmi > 40
|
131
|
-
msj= "Obese Class III"
|
132
|
-
end
|
133
|
-
return msj
|
134
|
-
end
|
135
|
-
|
136
|
-
def calc(arguments=[])
|
137
|
-
|
138
|
-
loadata(arguments)
|
139
|
-
determinates()
|
140
|
-
|
141
|
-
if @imperial
|
142
|
-
get_imperial()
|
143
|
-
get_prime()
|
144
|
-
cases()
|
145
|
-
end
|
146
|
-
|
147
|
-
if @metric
|
148
|
-
get_metric()
|
149
|
-
get_prime()
|
150
|
-
cases()
|
151
|
-
end
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
VERSION = '0.1.2'
|
156
|
-
end
|
157
|
-
|
7
|
+
VERSION = '0.2.0'
|
data/lib/bmi/bmi.rb
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
class BMI
|
2
|
+
|
3
|
+
attr_accessor :data, :metric, :imperial, :bmi, :metric, :percent, :errors, :errtype
|
4
|
+
|
5
|
+
def initialize(data={})
|
6
|
+
@data = data
|
7
|
+
|
8
|
+
@data = {
|
9
|
+
:weight_k => 0,
|
10
|
+
:height_m => 0,
|
11
|
+
:weight_p => 0,
|
12
|
+
:height_i => 0
|
13
|
+
}
|
14
|
+
|
15
|
+
@errors = {
|
16
|
+
:Exists => false,
|
17
|
+
:Missing => "Error: You must put a weight and a height !",
|
18
|
+
:Mismatch => "Error: Arguments must be Numbers !",
|
19
|
+
:Amount => "Error: Two diferent arguments expected",
|
20
|
+
:Height => "Error: Use 'm'|'M' for 'meters' or 'i'|'I' for 'inches'",
|
21
|
+
:Weight => "Error: Use 'k'|'K' for 'kilograms' or 'p'|'P' for 'pounds'",
|
22
|
+
:Wrong => "Use '-h' or '--help' for more help"
|
23
|
+
}
|
24
|
+
|
25
|
+
@errtype=[]
|
26
|
+
@imperial = false
|
27
|
+
@metric = false
|
28
|
+
@weight = 0
|
29
|
+
@height = 0
|
30
|
+
@bmi = 0
|
31
|
+
@prime = 0
|
32
|
+
@percent = 0
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def height(height, type="m")
|
38
|
+
@data[:height_m]=@data[:height_i]=0
|
39
|
+
@errors[:Exists] = false
|
40
|
+
@errtype=[]
|
41
|
+
unless type.to_s.match(/m|i|M|I/) && type.class==String
|
42
|
+
@errors[:Exists]=true
|
43
|
+
@errtype<<:Height
|
44
|
+
end
|
45
|
+
if height.to_s.match(/\d/) && !@errors[:Exists]
|
46
|
+
@data[:height_m]=height if type == "m" || type == "M"
|
47
|
+
@data[:height_i]=height if type == "i" || type == "I"
|
48
|
+
elsif !height.to_s.match(/\d/)
|
49
|
+
@errors[:Exists]=true
|
50
|
+
@errtype<<:Mismatch
|
51
|
+
end
|
52
|
+
|
53
|
+
return !@errors[:Exists]
|
54
|
+
end
|
55
|
+
|
56
|
+
def weight(weight, type="k")
|
57
|
+
@data[:weight_k]=@data[:weight_p]=0
|
58
|
+
@errors[:Exists] = false
|
59
|
+
@errtype=[]
|
60
|
+
unless type.to_s.match(/k|p|K|P/) && type.class==String
|
61
|
+
@errors[:Exists]=true
|
62
|
+
@errtype<<:Weight
|
63
|
+
end
|
64
|
+
if weight.to_s.match(/\d/) && !@errors[:Exists]
|
65
|
+
@data[:weight_k]=weight if type == "k" || type == "K"
|
66
|
+
@data[:weight_p]=weight if type == "p" || type == "P"
|
67
|
+
elsif !weight.to_s.match(/\d/)
|
68
|
+
@errors[:Exists]=true
|
69
|
+
@errtype<<:Mismatch
|
70
|
+
end
|
71
|
+
|
72
|
+
return !@errors[:Exists]
|
73
|
+
end
|
74
|
+
|
75
|
+
def determinates
|
76
|
+
@metric=@imperial=false if error
|
77
|
+
data = @data.select{|k,v| v.to_f > 0}
|
78
|
+
@imperial = true if data[:weight_p] && data[:height_i]
|
79
|
+
@metric = true if data[:weight_k] && data[:height_m]
|
80
|
+
@weight = data[:weight_k] || data[:weight_p]
|
81
|
+
@height = data[:height_m] || data[:height_i]
|
82
|
+
@weight = @weight.to_f
|
83
|
+
@height = @height.to_f
|
84
|
+
return "Imperial" if @imperial
|
85
|
+
return "Metric" if @metric
|
86
|
+
return "None" if @imperial == @metric
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_imperial
|
90
|
+
if determinates == "Imperial"
|
91
|
+
@bmi =( ( @weight ) / ( @height * @height ) ) * 703
|
92
|
+
return @bmi
|
93
|
+
elsif @weight == 0 || @height == 0
|
94
|
+
@errors[:Exists]=true
|
95
|
+
@errtype<<:Amount
|
96
|
+
return false
|
97
|
+
else
|
98
|
+
return false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_metric
|
103
|
+
if determinates == "Metric"
|
104
|
+
@bmi =( @weight ) / ( @height * @height )
|
105
|
+
return @bmi
|
106
|
+
elsif @weight == 0 || @height == 0
|
107
|
+
@errors[:Exists]=true
|
108
|
+
@errtype<<:Amount
|
109
|
+
return false
|
110
|
+
else
|
111
|
+
return false
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def error
|
116
|
+
return @errors[:Exists]
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_errors
|
120
|
+
@errtype.uniq!
|
121
|
+
display = []
|
122
|
+
@errtype.each do |k|
|
123
|
+
display<<@errors[k]
|
124
|
+
end
|
125
|
+
return display.shift
|
126
|
+
end
|
127
|
+
|
128
|
+
def get_prime
|
129
|
+
if @bmi > 0
|
130
|
+
@prime = ( @bmi / 25 )
|
131
|
+
prti = @prime.to_s.match(/\d+/)
|
132
|
+
ceros = @prime.to_s.match(/\.(0+)/)
|
133
|
+
if !ceros
|
134
|
+
ceros = []
|
135
|
+
ceros[1] = "0"
|
136
|
+
end
|
137
|
+
prcnt = @prime.to_s.match(/\.(\d{1,2})/)
|
138
|
+
if prti[0].to_i <= 0
|
139
|
+
@percent = (100)*(ceros[1].length) - (prcnt[1].to_i)
|
140
|
+
return @percent.to_s+"% under your ideal weight"
|
141
|
+
else
|
142
|
+
@percent = prcnt[1].to_i + (100*(prti[0].to_i-1))
|
143
|
+
return @percent.to_s+"% over your ideal weight"
|
144
|
+
end
|
145
|
+
else
|
146
|
+
return false
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def cases
|
151
|
+
if @bmi > 0
|
152
|
+
case
|
153
|
+
when @bmi < 18.5
|
154
|
+
msj= "Underweight"
|
155
|
+
when @bmi.between?(18.5,25)
|
156
|
+
msj= "Normal"
|
157
|
+
when @bmi.between?(25,30)
|
158
|
+
msj= "Overweight"
|
159
|
+
when @bmi.between?(30,35)
|
160
|
+
msj= "Obese Class I"
|
161
|
+
when @bmi.between?(35,40)
|
162
|
+
msj= "Obese Class II"
|
163
|
+
when @bmi > 40
|
164
|
+
msj= "Obese Class III"
|
165
|
+
end
|
166
|
+
return msj
|
167
|
+
else
|
168
|
+
return false
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def calc
|
173
|
+
if determinates == "Imperial"
|
174
|
+
puts "Your body mass index is: "+get_imperial.to_i.to_s
|
175
|
+
puts "You are "+get_prime
|
176
|
+
puts "Your status is :"+cases
|
177
|
+
return true
|
178
|
+
end
|
179
|
+
if determinates == "Metric"
|
180
|
+
puts "Your body mass index is: "+get_metric.to_i.to_s
|
181
|
+
puts "You are "+get_prime
|
182
|
+
puts "Your status is :"+cases
|
183
|
+
return true
|
184
|
+
end
|
185
|
+
return get_errors if error
|
186
|
+
return false unless @data.select{|k,v| v.to_f > 0}.count > 0
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
data/lib/bmi/cli.rb
CHANGED
@@ -4,6 +4,8 @@ module Bmi
|
|
4
4
|
class CLI
|
5
5
|
def self.calc(arguments=[])
|
6
6
|
|
7
|
+
|
8
|
+
|
7
9
|
options = {
|
8
10
|
:weight_k => 0,
|
9
11
|
:height_m => 0,
|
@@ -27,7 +29,6 @@ module Bmi
|
|
27
29
|
"Pleace introduce your weight in kilograms.",
|
28
30
|
"Default: ~") { |arg| options[:weight_k] = arg }
|
29
31
|
|
30
|
-
|
31
32
|
opts.on("-b", "--height METERS", String,
|
32
33
|
"How hight you are.",
|
33
34
|
"Pleace introduce your height in meters.",
|
@@ -46,14 +47,27 @@ module Bmi
|
|
46
47
|
opts.on("-h", "--help",
|
47
48
|
"Show this help message.") { puts opts; exit }
|
48
49
|
|
49
|
-
|
50
|
+
|
51
|
+
error = false
|
52
|
+
arguments.each do|v|
|
53
|
+
unless v.match(/-[w|b|W|B|h]/) || v.match(/\d/)
|
54
|
+
error = true
|
55
|
+
puts "Use '-h' or '--help' for more help"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
unless (arguments[0] == "-h") || (arguments[0] == "--help")
|
60
|
+
error = true unless (arguments.count == 4)
|
61
|
+
end
|
62
|
+
|
63
|
+
opts.parse!(arguments) unless error
|
50
64
|
|
51
65
|
if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
|
52
66
|
puts opts; exit
|
53
67
|
end
|
54
68
|
end
|
55
69
|
|
56
|
-
|
70
|
+
return options
|
57
71
|
end
|
58
72
|
end
|
59
73
|
end
|
data/test/test_bmi.rb
CHANGED
@@ -5,38 +5,80 @@ class TestBmi < Test::Unit::TestCase
|
|
5
5
|
|
6
6
|
#def setup
|
7
7
|
#end
|
8
|
-
@@bmi=BMI.new
|
9
8
|
|
10
9
|
def test_truth
|
11
10
|
assert true
|
12
11
|
end
|
13
12
|
|
14
|
-
def
|
15
|
-
|
16
|
-
assert_equal(true
|
13
|
+
def test_height
|
14
|
+
@bmi=BMI.new
|
15
|
+
assert_equal(true,@bmi.height(80,'m'))
|
16
|
+
assert_equal(true,@bmi.height(80,'i'))
|
17
|
+
assert_equal(true,@bmi.height(80,'M'))
|
18
|
+
assert_equal(true,@bmi.height(80,'I'))
|
19
|
+
assert_equal(true,@bmi.height(80))
|
17
20
|
end
|
18
21
|
|
19
|
-
def
|
20
|
-
|
21
|
-
assert_equal(true
|
22
|
+
def test_weight
|
23
|
+
@bmi=BMI.new
|
24
|
+
assert_equal(true,@bmi.weight(80,'k'))
|
25
|
+
assert_equal(true,@bmi.weight(80,'p'))
|
26
|
+
assert_equal(true,@bmi.weight(80,'K'))
|
27
|
+
assert_equal(true,@bmi.weight(80,'P'))
|
28
|
+
assert_equal(true,@bmi.weight(80))
|
22
29
|
end
|
23
30
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
31
|
+
def test_determinates
|
32
|
+
@bmi=BMI.new
|
33
|
+
@bmi.weight(189.597,'p')
|
34
|
+
@bmi.height(1.7)
|
35
|
+
assert_equal("None",@bmi.determinates)
|
36
|
+
@bmi.weight(80)
|
37
|
+
@bmi.height(1.7)
|
38
|
+
assert_equal("Metric",@bmi.determinates)
|
39
|
+
@bmi.weight(189.597,'p')
|
40
|
+
@bmi.height(69.6850,'i')
|
41
|
+
assert_equal("Imperial",@bmi.determinates)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_get_imperial
|
45
|
+
@bmi=BMI.new
|
46
|
+
@bmi.weight(189.597,'p')
|
47
|
+
@bmi.height(69.6850,'i')
|
48
|
+
assert_equal(27.447840253722447,@bmi.get_imperial)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_get_metric
|
52
|
+
@bmi=BMI.new
|
53
|
+
@bmi.weight(80)
|
54
|
+
@bmi.height(1.7)
|
55
|
+
assert_equal(27.68166089965398,@bmi.get_metric)
|
27
56
|
end
|
28
57
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
'Obese Class III' =>['-w 120','-b 1.70']}
|
36
|
-
|
37
|
-
cases.each do |k,v|
|
38
|
-
@@bmi.calc(v)
|
39
|
-
assert_equal(k,@@bmi.cases)
|
40
|
-
end
|
58
|
+
def test_get_prime
|
59
|
+
@bmi=BMI.new
|
60
|
+
@bmi.weight(80)
|
61
|
+
@bmi.height(1.7)
|
62
|
+
@bmi.get_metric
|
63
|
+
assert_equal("10% over your ideal weight",@bmi.get_prime)
|
41
64
|
end
|
65
|
+
|
66
|
+
def test_categories_cases
|
67
|
+
@bmi=BMI.new
|
68
|
+
@bmi.weight(80)
|
69
|
+
@bmi.height(1.7)
|
70
|
+
cases={'Underweight' =>[50,1.70],
|
71
|
+
'Normal' =>[60,1.70],
|
72
|
+
'Overweight' =>[75,1.70],
|
73
|
+
'Obese Class I' =>[90,1.70],
|
74
|
+
'Obese Class II' =>[105,1.70],
|
75
|
+
'Obese Class III' =>[120,1.70]}
|
76
|
+
|
77
|
+
cases.each do |k,v|
|
78
|
+
@bmi.weight(v[0])
|
79
|
+
@bmi.height(v[1])
|
80
|
+
@bmi.get_metric
|
81
|
+
assert_equal(k,@bmi.cases)
|
82
|
+
end
|
83
|
+
end
|
42
84
|
end
|
data/test/test_bmi_cli.rb
CHANGED
@@ -7,27 +7,27 @@ class TestBmiCli < Test::Unit::TestCase
|
|
7
7
|
Bmi::CLI.calc([])
|
8
8
|
end
|
9
9
|
|
10
|
-
def test_kilograms
|
11
|
-
data = Bmi::CLI.calc(['-w 80'])
|
12
|
-
kilograms = data[:weight_k].to_f
|
13
|
-
assert_equal(80, kilograms)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_meters
|
17
|
-
data = Bmi::CLI.calc(['-b 1.80'])
|
18
|
-
meters = data[:height_m].to_f
|
19
|
-
assert_equal(1.80, meters)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_pounds
|
23
|
-
data = Bmi::CLI.calc(['-W 166'])
|
24
|
-
pounds = data[:weight_p].to_f
|
25
|
-
assert_equal(166, pounds)
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_inches
|
29
|
-
data = Bmi::CLI.calc(['-B 68.11'])
|
30
|
-
inches = data[:height_i].to_f
|
31
|
-
assert_equal(68.11, inches)
|
32
|
-
end
|
10
|
+
# def test_kilograms
|
11
|
+
# data = Bmi::CLI.calc(['-w 80'])
|
12
|
+
# kilograms = data[:weight_k].to_f
|
13
|
+
# assert_equal(80, kilograms)
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# def test_meters
|
17
|
+
# data = Bmi::CLI.calc(['-b 1.80'])
|
18
|
+
# meters = data[:height_m].to_f
|
19
|
+
# assert_equal(1.80, meters)
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def test_pounds
|
23
|
+
# data = Bmi::CLI.calc(['-W 166'])
|
24
|
+
# pounds = data[:weight_p].to_f
|
25
|
+
# assert_equal(166, pounds)
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# def test_inches
|
29
|
+
# data = Bmi::CLI.calc(['-B 68.11'])
|
30
|
+
# inches = data[:height_i].to_f
|
31
|
+
# assert_equal(68.11, inches)
|
32
|
+
# end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bmi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-26 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: hoe
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156549880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.12'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156549880
|
25
25
|
description: The Body Mass Index (BMI) Gem is usefull to calculate your BMI from console,
|
26
26
|
and add this gem to your ruby project and use it. See 'bmi -h' to read the instructions
|
27
27
|
of usage.
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- bin/bmi
|
44
44
|
- lib/bmi.rb
|
45
45
|
- lib/bmi/cli.rb
|
46
|
+
- lib/bmi/bmi.rb
|
46
47
|
- script/console
|
47
48
|
- script/destroy
|
48
49
|
- script/generate
|