Class: Plato_i
- Inherits:
-
Object
- Object
- Plato_i
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/p6/plato.rb
Overview
La clase plato_i almacena dos listas: alimentos y pesos
Direct Known Subclasses
Instance Attribute Summary collapse
-
#alimentos_ ⇒ Object
Returns the value of attribute alimentos_.
-
#nombre_ ⇒ Object
Returns the value of attribute nombre_.
-
#peso_ ⇒ Object
Returns the value of attribute peso_.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Metodo comparable.
-
#initialize(string, alimentos, peso) ⇒ Plato_i
constructor
Constructor de la clase Plato_i.
-
#porc_carbo ⇒ Object
Porcentaje de carbohidratos.
-
#porc_lipidos ⇒ Object
Porcentaje de lipidos.
-
#porc_proteinas ⇒ Object
Porcentaje de proteinas.
-
#vct ⇒ Object
Valor calórico total.
Constructor Details
#initialize(string, alimentos, peso) ⇒ Plato_i
Constructor de la clase Plato_i
9 10 11 12 13 14 15 |
# File 'lib/p6/plato.rb', line 9 def initialize(string, alimentos, peso) @nombre_ = string @alimentos_ = List.new @peso_ = List.new @alimentos_.insert_many(alimentos) @peso_.insert_many(peso) end |
Instance Attribute Details
#alimentos_ ⇒ Object
Returns the value of attribute alimentos_.
6 7 8 |
# File 'lib/p6/plato.rb', line 6 def alimentos_ @alimentos_ end |
#nombre_ ⇒ Object
Returns the value of attribute nombre_.
6 7 8 |
# File 'lib/p6/plato.rb', line 6 def nombre_ @nombre_ end |
#peso_ ⇒ Object
Returns the value of attribute peso_.
6 7 8 |
# File 'lib/p6/plato.rb', line 6 def peso_ @peso_ end |
Instance Method Details
#<=>(other) ⇒ Object
Metodo comparable
70 71 72 |
# File 'lib/p6/plato.rb', line 70 def <=>(other) vct <=> other.vct end |
#porc_carbo ⇒ Object
Porcentaje de carbohidratos
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/p6/plato.rb', line 34 def porc_carbo total_carb = 0 total_macro = 0 @alimentos_.zip(peso_).collect{|alimento, peso| total_carb += (peso * alimento.carbo_) / 100 total_macro += (peso * alimento.carbo_) / 100 + (peso * alimento.proteinas_) / 100 + (peso * alimento.lipidos_) / 100 } return (total_carb / total_macro) * 100 end |
#porc_lipidos ⇒ Object
Porcentaje de lipidos
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/p6/plato.rb', line 47 def porc_lipidos total_lipidos = 0 total_macro = 0 @alimentos_.zip(peso_).collect{|alimento, peso| total_lipidos += (peso * alimento.lipidos_) / 100 total_macro += (peso * alimento.carbo_) / 100 + (peso * alimento.proteinas_) / 100 + (peso * alimento.lipidos_) / 100 } return (total_lipidos / total_macro) * 100 end |
#porc_proteinas ⇒ Object
Porcentaje de proteinas
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/p6/plato.rb', line 18 def porc_proteinas total_prot = 0 total_macro = 0 total_prot = @alimentos_.zip(peso_).collect{|alimento, peso| (peso * alimento.proteinas_) / 100 }.reduce(:+) total_macro = @alimentos_.zip(peso_).collect{|alimento, peso| (peso * alimento.carbo_) / 100 + (peso * alimento.proteinas_) / 100 + (peso * alimento.lipidos_) / 100 }.reduce(:+) return (total_prot / total_macro) * 100 end |
#vct ⇒ Object
Valor calórico total
60 61 62 63 64 65 66 67 |
# File 'lib/p6/plato.rb', line 60 def vct total = 0 total = alimentos_.zip(peso_).collect{| alimento, peso | (alimento.calorias * peso) / 100 }.reduce(:+) return total end |