Module: BmiCalculator

Defined in:
lib/bmi_calculator.rb,
lib/bmi_calculator/convert.rb,
lib/bmi_calculator/version.rb

Defined Under Namespace

Classes: Convert

Constant Summary collapse

VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.calc_cm(height, weight, round = 1) ⇒ float

calc bmi.

Parameters:

  • height (integer)

    height(cm)

  • weight (float)

    weight(kg)

  • round (integer) (defaults to: 1)

    round number

Returns:

  • (float)

    bmi



22
23
24
25
26
27
28
# File 'lib/bmi_calculator.rb', line 22

def self.calc_cm(height, weight, round=1)

  height_m = (height / 100.0).round(2)

  bmi = weight / (height_m * height_m)
  bmi.round(round)
end

.calc_cm_g(height, weight, round = 1) ⇒ float

calc bmi.

Parameters:

  • height (integer)

    height(cm)

  • weight (float)

    weight(g)

  • round (integer) (defaults to: 1)

    round number

Returns:

  • (float)

    bmi



35
36
37
38
39
40
41
42
# File 'lib/bmi_calculator.rb', line 35

def self.calc_cm_g(height, weight, round=1)

  height_m = (height / 100.0).round(2)
  weight_kg = (weight / 1000.0).round(1)

  bmi = weight_kg / (height_m * height_m)
  bmi.round(round)
end

.calc_feet_yp(height, weight, round = 1) ⇒ float

calc bmi by yard-pound.

Parameters:

  • height (integer)

    height(feet)

  • weight (float)

    weight(pound)

  • round (integer) (defaults to: 1)

    round number

Returns:

  • (float)

    bmi



63
64
65
66
67
68
69
# File 'lib/bmi_calculator.rb', line 63

def self.calc_feet_yp(height, weight, round=1)

  # convert to inch.
  height_in = BmiCalculator::Convert.feet_to_inch(height)
  # calc bmi.
  calc_inner_yp(height_in, weight, round)
end

.calc_inch_yp(height, weight, round = 1) ⇒ float

calc bmi by yard-pound.

Parameters:

  • height (integer)

    height(inch)

  • weight (float)

    weight(pound)

  • round (integer) (defaults to: 1)

    round number

Returns:

  • (float)

    bmi



76
77
78
79
80
# File 'lib/bmi_calculator.rb', line 76

def self.calc_inch_yp(height, weight, round=1)

  # calc bmi.
  calc_inner_yp(height * 1.0, weight, round)
end

.calc_m(height, weight, round = 1) ⇒ float

calc bmi.

Parameters:

  • height (float)

    height(m)

  • weight (float)

    weight(kg)

  • round (intenger) (defaults to: 1)

    round number

Returns:

  • (float)

    bmi



11
12
13
14
15
# File 'lib/bmi_calculator.rb', line 11

def self.calc_m(height, weight, round=1)

  bmi = weight / (height * height)
  bmi.round(round)
end

.calc_yp(height_ft, height_in, weight, round = 1) ⇒ float

calc bmi by yard-pound.

Parameters:

  • height_ft (integer)

    height(feet)

  • height_in (integer)

    height(inch)

  • weight (float)

    weight(pound)

  • round (integer) (defaults to: 1)

    round number

Returns:

  • (float)

    bmi



50
51
52
53
54
55
56
# File 'lib/bmi_calculator.rb', line 50

def self.calc_yp(height_ft, height_in, weight, round=1)

  # 1feet = 12inch
  height = (BmiCalculator::Convert.feet_to_inch(height_ft) + height_in) * 1.0
  # calc bmi.
  calc_inner_yp(height, weight, round)
end