class Bmicalc

Constants

CLASSIFICATIONS
SUB_CLASSIFICATIONS
VERSION

Public Class Methods

new(options = {}) click to toggle source
# File lib/bmicalc.rb, line 34
def initialize(options = {})
  @bmi_calculator = options.fetch(:units, :metric) == :metric ? MetricBMI.new : ImperialBMI.new
end

Public Instance Methods

calculate(weight, height) click to toggle source
# File lib/bmicalc.rb, line 38
def calculate(weight, height)
  @bmi_calculator.calculate(weight, height)
end
classification(bmi) click to toggle source
# File lib/bmicalc.rb, line 42
def classification(bmi)
  find_classification(CLASSIFICATIONS, 'obese', bmi)
end
sub_classification(bmi) click to toggle source
# File lib/bmicalc.rb, line 46
def sub_classification(bmi)
  find_classification(SUB_CLASSIFICATIONS, 'obese class III', bmi)
end

Private Instance Methods

find_classification(classifications, default, bmi) click to toggle source
# File lib/bmicalc.rb, line 51
def find_classification(classifications, default, bmi)
  classifications.each do |bmi_limit, name|
    if bmi < bmi_limit
      return name
    end
  end

  return default
end