Class: BMI Abstract

Inherits:
Object
  • Object
show all
Includes:
YABMI
Defined in:
lib/bmi.rb,
lib/bmi/who.rb,
lib/bmi/jasso.rb,
lib/bmi/commonrisk.rb

Overview

This class is abstract.

Immutable

Direct Known Subclasses

JASSO, WHO

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.

Parameters:

  • index (Number)

Raises:

  • (RangeError)


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

Parameters:

  • weight_kg (Number)
  • height_m (Number)

Returns:



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: ===

Returns:

  • (Boolean)


58
59
60
# File 'lib/bmi.rb', line 58

def ==(other)
  other.respond_to?(:bmi?) && other.bmi? && (other.index == index)
end

#bmi?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/bmi.rb', line 39

def bmi?
  true
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/bmi.rb', line 53

def eql?(other)
  other.respond_to?(:bmi?) && other.bmi? && (other._index == _index)
end

#hashNumber

Returns:

  • (Number)


65
66
67
# File 'lib/bmi.rb', line 65

def hash
  @index.hash
end

#indexFloat Also known as: bmi

Returns:

  • (Float)


33
34
35
# File 'lib/bmi.rb', line 33

def index
  @index.to_f.round(1)
end

#inspectString

Returns:

  • (String)


44
45
46
# File 'lib/bmi.rb', line 44

def inspect
  "#<#{self.class}: #{index}(#{risk})>"
end

#to_sString

Returns:

  • (String)


49
50
51
# File 'lib/bmi.rb', line 49

def to_s
  index.to_s
end