Class: Calculato::BMICalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/calculato/bmi_calculator.rb

Constant Summary collapse

CATEGORIES =
{
  0..15 => 'Very severely underweight',
  15..16 => 'Severely underweight',
  16..18.5 => 'Underweight',
  18.5..25 => 'Normal (healthy weight)',
  25..30 => 'Overweight',
  30..35 => 'Obese Class I (Moderately obese)',
  35..40 => 'Obese Class II (Severely obese)',
  40..45 => 'Obese Class III (Very severely obese)',
  45..50 => 'Obese Class IV (Morbidly Obese)',
  50..60 => 'Obese Class V (Super Obese)',
  60..99 => 'Obese Class VI (Hyper Obese)'
}.freeze

Class Method Summary collapse

Class Method Details

.calculate(feet, inches, weight) ⇒ Object



19
20
21
22
# File 'lib/calculato/bmi_calculator.rb', line 19

def self.calculate(feet, inches, weight)
  inches = (inches + (feet * 12)).to_f
  short_calculate(inches, weight)
end

.category(bmi) ⇒ Object



28
29
30
# File 'lib/calculato/bmi_calculator.rb', line 28

def self.category(bmi)
  CATEGORIES.find { |key, value| break value if key.cover?(bmi) }
end

.short_calculate(inches, weight) ⇒ Object



24
25
26
# File 'lib/calculato/bmi_calculator.rb', line 24

def self.short_calculate(inches, weight)
  (703.0 * (weight.to_f / inches**2)).round(1)
end