Class: BMI
Abstract
- Inherits:
-
Object
show all
- Includes:
- YABMI
- Defined in:
- lib/bmi.rb,
lib/bmi/who.rb,
lib/bmi/jasso.rb,
lib/bmi/commonrisk.rb
Overview
Defined Under Namespace
Modules: CommonRisk
Classes: JASSO, WHO
Constant Summary
collapse
- USA =
WHO
- Japan =
JASSO
Constants included
from YABMI
YABMI::VERSION
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(index) ⇒ BMI
Returns a new instance of BMI.
26
27
28
29
30
|
# File 'lib/bmi.rb', line 26
def initialize(index)
raise RangeError unless index > 0
@index = index.to_r
end
|
Class Method Details
.calc(weight_kg, height_m) ⇒ BMI
19
20
21
22
|
# File 'lib/bmi.rb', line 19
def calc(weight_kg, height_m)
concrete = (equal?(BMI) ? WHO : self)
concrete.new(weight_kg.to_r / (height_m.to_r ** 2))
end
|
Instance Method Details
#==(other) ⇒ Boolean
Also known as:
===
58
59
60
|
# File 'lib/bmi.rb', line 58
def ==(other)
other.respond_to?(:bmi?) && other.bmi? && (other.index == index)
end
|
#bmi? ⇒ Boolean
39
40
41
|
# File 'lib/bmi.rb', line 39
def bmi?
true
end
|
#eql?(other) ⇒ Boolean
53
54
55
|
# File 'lib/bmi.rb', line 53
def eql?(other)
other.respond_to?(:bmi?) && other.bmi? && (other._index == _index)
end
|
#hash ⇒ Number
65
66
67
|
# File 'lib/bmi.rb', line 65
def hash
@index.hash
end
|
#index ⇒ Float
Also known as:
bmi
33
34
35
|
# File 'lib/bmi.rb', line 33
def index
@index.to_f.round(1)
end
|
#inspect ⇒ String
44
45
46
|
# File 'lib/bmi.rb', line 44
def inspect
"#<#{self.class}: #{index}(#{risk})>"
end
|
#to_s ⇒ String
49
50
51
|
# File 'lib/bmi.rb', line 49
def to_s
index.to_s
end
|