Class: Alimento::Plato
- Inherits:
-
Object
- Object
- Alimento::Plato
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/alimento/plato.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cantidades ⇒ Object
readonly
Returns the value of attribute cantidades.
-
#lista ⇒ Object
readonly
Returns the value of attribute lista.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
Instance Method Summary collapse
-
#<=>(otro) ⇒ Object
Plato con mayor contenido en kcal.
-
#initialize(nombre, lista, cantidades) ⇒ Plato
constructor
A new instance of Plato.
-
#porcentaje_carbohidratos ⇒ Float
Porcentaje de carbohidratos.
-
#porcentaje_lipidos ⇒ Float
Porcentaje de lipidos.
-
#porcentaje_proteinas ⇒ Float
Porcentaje de proteinas.
-
#to_s ⇒ String
El nombre del plato y los alimentos que lo componen.
-
#VCT ⇒ Float
Valor total de kcal.
Constructor Details
#initialize(nombre, lista, cantidades) ⇒ Plato
Constructor de la clase
Returns a new instance of Plato
16 17 18 |
# File 'lib/alimento/plato.rb', line 16 def initialize(nombre, lista, cantidades) @nombre, @lista, @cantidades = nombre, lista, cantidades end |
Instance Attribute Details
#cantidades ⇒ Object (readonly)
Returns the value of attribute cantidades
9 10 11 |
# File 'lib/alimento/plato.rb', line 9 def cantidades @cantidades end |
#lista ⇒ Object (readonly)
Returns the value of attribute lista
9 10 11 |
# File 'lib/alimento/plato.rb', line 9 def lista @lista end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre
9 10 11 |
# File 'lib/alimento/plato.rb', line 9 def nombre @nombre end |
Instance Method Details
#<=>(otro) ⇒ Object
Comparador de platos
Returns Plato con mayor contenido en kcal
23 24 25 |
# File 'lib/alimento/plato.rb', line 23 def <=>(otro) VCT() <=> otro.VCT end |
#porcentaje_carbohidratos ⇒ Float
Calculo del procentaje de carbohidratos del plato
Returns Porcentaje de carbohidratos
56 57 58 59 60 61 62 63 64 |
# File 'lib/alimento/plato.rb', line 56 def porcentaje_carbohidratos total = VCT() carbohidratos = i = 0 lista.each{|iter| carbohidratos += iter.value.valor_glucidos(iter.value.carbohidratos * @cantidades[i]/100) i += 1} return ((carbohidratos * 100) / total).round(1) end |
#porcentaje_lipidos ⇒ Float
Calculo del procentaje de lipidos del plato
Returns Porcentaje de lipidos
69 70 71 72 73 74 75 76 77 |
# File 'lib/alimento/plato.rb', line 69 def porcentaje_lipidos total = VCT() lipidos = i = 0 lista.each{|iter| lipidos += iter.value.valor_lipidos(iter.value.lipidos * @cantidades[i]/100) i += 1} return ((lipidos * 100) / total).round(1) end |
#porcentaje_proteinas ⇒ Float
Calculo del procentaje de proteinas del plato
Returns Porcentaje de proteinas
43 44 45 46 47 48 49 50 51 |
# File 'lib/alimento/plato.rb', line 43 def porcentaje_proteinas total = VCT() proteinas = i = 0 lista.each{|iter| proteinas += iter.value.valor_proteinas(iter.value.proteinas * @cantidades[i]/100) i += 1} return ((proteinas * 100) / total).round(1) end |
#to_s ⇒ String
Formateo del plato
Returns El nombre del plato y los alimentos que lo componen
82 83 84 85 86 87 88 89 90 |
# File 'lib/alimento/plato.rb', line 82 def to_s string = "Plato: #{nombre}, Componentes: " i = 0 lista.collect{|iter| string += "'#{iter.value.nombre} (#{cantidades[i]}g)' " i += 1 } return string end |
#VCT ⇒ Float
Calculo de las kcal totales de cada plato con sus cantidades
Returns Valor total de kcal
30 31 32 33 34 35 36 37 38 |
# File 'lib/alimento/plato.rb', line 30 def VCT total_kcal = 0 i = 0 @lista.each{ |iter| total_kcal += (iter.value.valor_energetico(iter.value.valor_glucidos(iter.value.carbohidratos), iter.value.valor_proteinas(iter.value.proteinas), iter.value.valor_lipidos(iter.value.lipidos)) * @cantidades[i]/100) i += 1 } return total_kcal.round(1) end |