Class: Diet
Overview
Diet Object to see if a persins gets enough nutrients
Instance Attribute Summary collapse
-
#food_energy ⇒ Object
getter and setter.
-
#gasto_energetico_total ⇒ Object
getter and setter.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#analize ⇒ string
[Returns a nice readeable output with the evaluated data and the result.].
- #eat(it) ⇒ Object
-
#initialize(anthropometric) ⇒ nil
constructor
[nothing].
-
#sport(intensity) ⇒ Object
Sport function to change the factor of the physical activity.
Constructor Details
#initialize(anthropometric) ⇒ nil
Returns [nothing].
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/prct06/diet.rb', line 24 def initialize(anthropometric) @peso_teorico_ideal = (anthropometric.height - 150) * 0.75 + 50 @gasto_energetico_basal = (10 * anthropometric.weight) + (6.25 * anthropometric.height) - (5 * anthropometric.age) + ((anthropometric.sex==1)? -161 : 5) @efecto_termogeno = @gasto_energetico_basal * 0.1 @factor_actividad_fisica = 0.0 @gasto_actividad_fisica = @gasto_energetico_basal * @factor_actividad_fisica @gasto_energetico_total = @gasto_energetico_basal * @efecto_termogeno + @gasto_actividad_fisica @food = Liste.new() @food_energy = 0.0 end |
Instance Attribute Details
#food_energy ⇒ Object
getter and setter
10 11 12 |
# File 'lib/prct06/diet.rb', line 10 def food_energy @food_energy end |
#gasto_energetico_total ⇒ Object
getter and setter
10 11 12 |
# File 'lib/prct06/diet.rb', line 10 def gasto_energetico_total @gasto_energetico_total end |
Instance Method Details
#<=>(other) ⇒ Object
84 85 86 87 |
# File 'lib/prct06/diet.rb', line 84 def <=> (other) return nil unless other.is_a?Diet gasto_energetico_total <=> other.gasto_energetico_total end |
#analize ⇒ string
Returns [Returns a nice readeable output with the evaluated data and the result.].
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/prct06/diet.rb', line 71 def analize() difference = @gasto_energetico_total - @food_energy puts "Consumed Energy:\t#{@food_energy.round(2)}\nBurned Energy:\t\t#{@gasto_energetico_total.round(2)}\n\n" if difference.abs <= @gasto_energetico_total * 0.1 puts "La cantidad de la alimentación es suficiente para cubrir las exigencias calóricas del organismo y mantiene el equilibrio de su balance.\n Difference: #{difference.round(2)}" elsif @food_energy < @gasto_energetico_total puts "La cantidad de la alimentación no es suficiente para cubrir las exigencias calóricas del organismo.\nTomaste #{difference.round(2)}kcal/g muy poco." elsif @food_energy > @gasto_energetico_total puts "Ha consumido demasiado calóricas. No mantiene el equilibrio de su balance.\nTomaste #{difference.round(2)}kcal/g demasiado." else puts "Strange ERROR" end end |
#eat(it) ⇒ Object
40 41 42 43 |
# File 'lib/prct06/diet.rb', line 40 def eat(it) @food.push(it) @food_energy = @food.reduce(0) { |sum, obj| sum + obj.energy } end |
#sport(intensity) ⇒ Object
Sport function to change the factor of the physical activity
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/prct06/diet.rb', line 50 def sport(intensity) if intensity == 0 || intensity == "reposo" @factor_actividad_fisica = 0.0 elsif intensity == 1 || intensity == "ligera" @factor_actividad_fisica = 0.12 elsif intensity == 2 || intensity == "moderada" @factor_actividad_fisica = 0.27 elsif intensity == 3 || intensity == "intensa" @factor_actividad_fisica = 0.54 else puts "Input doesn't make sence!" end @gasto_actividad_fisica = @gasto_energetico_basal * @factor_actividad_fisica @gasto_energetico_total = @gasto_energetico_basal * @efecto_termogeno + @gasto_actividad_fisica end |