Class: Calculator
- Inherits:
-
Object
- Object
- Calculator
- Defined in:
- lib/wilks_calc/calculator.rb
Constant Summary collapse
- COEFFICIENTS =
{ 'A': { 'M': -216.0475144, 'F': 594.31747775582 }, 'B': { 'M': 16.2606339, 'F': -27.23842536447 }, 'C': { 'M': -0.002388645, 'F': 0.82112226871 }, 'D': { 'M': -0.00113732, 'F': -0.00930733913 }, 'E': { 'M': ("%.11f" % "7.01863e-06").to_f, 'F': ("%.15f" % "4.731582e-05").to_f }, 'F': { 'M': ("%.13f" % "-1.291e-08").to_f, 'F': ("%.15f" % "-9.054E-08").to_f } }
Instance Attribute Summary collapse
-
#bw ⇒ Object
readonly
Returns the value of attribute bw.
-
#sex ⇒ Object
readonly
Returns the value of attribute sex.
-
#wl ⇒ Object
readonly
Returns the value of attribute wl.
Instance Method Summary collapse
- #calculate ⇒ Object
- #coeff_calculator ⇒ Object
-
#initialize(sex, bodyweight, weight_lifted) ⇒ Calculator
constructor
A new instance of Calculator.
- #power(coeff, p) ⇒ Object
Constructor Details
#initialize(sex, bodyweight, weight_lifted) ⇒ Calculator
Returns a new instance of Calculator.
13 14 15 16 17 |
# File 'lib/wilks_calc/calculator.rb', line 13 def initialize(sex, bodyweight, weight_lifted) @sex = sex @bw = bodyweight.to_f @wl = weight_lifted.to_f end |
Instance Attribute Details
#bw ⇒ Object (readonly)
Returns the value of attribute bw.
2 3 4 |
# File 'lib/wilks_calc/calculator.rb', line 2 def bw @bw end |
#sex ⇒ Object (readonly)
Returns the value of attribute sex.
2 3 4 |
# File 'lib/wilks_calc/calculator.rb', line 2 def sex @sex end |
#wl ⇒ Object (readonly)
Returns the value of attribute wl.
2 3 4 |
# File 'lib/wilks_calc/calculator.rb', line 2 def wl @wl end |
Instance Method Details
#calculate ⇒ Object
19 20 21 |
# File 'lib/wilks_calc/calculator.rb', line 19 def calculate (wl * 500 / coeff_calculator).round(2) end |
#coeff_calculator ⇒ Object
23 24 25 26 27 |
# File 'lib/wilks_calc/calculator.rb', line 23 def coeff_calculator() ('A'..'F').to_a.each_with_index.reduce(0) do |memo, (coeff, index)| memo += power(coeff, index) end end |
#power(coeff, p) ⇒ Object
29 30 31 |
# File 'lib/wilks_calc/calculator.rb', line 29 def power(coeff, p) COEFFICIENTS[coeff.to_sym][sex.to_sym] * bw ** p end |