Class: Alimento::Plato
- Inherits:
-
Object
- Object
- Alimento::Plato
- Includes:
- Comparable
- Defined in:
- lib/alimento/plato.rb
Overview
Plato formado por cantidades de uno o más alimentos.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#listaAlimentos ⇒ Object
readonly
Returns the value of attribute listaAlimentos.
-
#listaGramos ⇒ Object
readonly
Returns the value of attribute listaGramos.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#getCarbohidratos ⇒ Object
Devuelve el total de carbohidratos del plato.
-
#getGramosTotales ⇒ Object
Devuelve la cantidad total de gramos del plato.
-
#getLipidos ⇒ Object
Devuelve el total de lípidos del plato.
-
#getProteinas ⇒ Object
Devuelve el total de proteínas del plato.
-
#getValorCaloricoTotal ⇒ Object
Devuelve el total del valor calórico del plato.
-
#initialize(nombre, listaAlimentos, listaGramos) ⇒ Plato
constructor
A new instance of Plato.
- #to_s ⇒ Object
Constructor Details
#initialize(nombre, listaAlimentos, listaGramos) ⇒ Plato
Returns a new instance of Plato.
9 10 11 12 13 |
# File 'lib/alimento/plato.rb', line 9 def initialize (nombre, listaAlimentos, listaGramos) @nombre = nombre @listaAlimentos = listaAlimentos @listaGramos = listaGramos end |
Instance Attribute Details
#listaAlimentos ⇒ Object (readonly)
Returns the value of attribute listaAlimentos.
8 9 10 |
# File 'lib/alimento/plato.rb', line 8 def listaAlimentos @listaAlimentos end |
#listaGramos ⇒ Object (readonly)
Returns the value of attribute listaGramos.
8 9 10 |
# File 'lib/alimento/plato.rb', line 8 def listaGramos @listaGramos end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
8 9 10 |
# File 'lib/alimento/plato.rb', line 8 def nombre @nombre end |
Instance Method Details
#<=>(other) ⇒ Object
79 80 81 82 83 |
# File 'lib/alimento/plato.rb', line 79 def <=>(other) if other != nil getValorCaloricoTotal <=> other.getValorCaloricoTotal end end |
#getCarbohidratos ⇒ Object
Devuelve el total de carbohidratos del plato.
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/alimento/plato.rb', line 43 def getCarbohidratos aux = listaAlimentos.head aux2 = listaGramos.head carbohidratos = 0 gramosTotales = 0 while aux != nil && listaGramos != nil carbohidratos += aux.value.carbohidratos * (aux2.value/100) gramosTotales = aux2.value aux = aux.next aux2 = aux2.next end return ((carbohidratos * 100)/gramosTotales).round(2) end |
#getGramosTotales ⇒ Object
Devuelve la cantidad total de gramos del plato.
57 58 59 60 61 62 63 64 65 |
# File 'lib/alimento/plato.rb', line 57 def getGramosTotales aux = listaGramos.head gramosTotales = 0 while aux != nil gramosTotales = aux.value aux = aux.next end return gramosTotales end |
#getLipidos ⇒ Object
Devuelve el total de lípidos del plato.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/alimento/plato.rb', line 29 def getLipidos aux = listaAlimentos.head aux2 = listaGramos.head lipidos = 0 gramosTotales = 0 while aux != nil && listaGramos != nil lipidos += aux.value.lipidos * (aux2.value/100) gramosTotales = aux2.value aux = aux.next aux2 = aux2.next end return ((lipidos * 100)/gramosTotales).round(2) end |
#getProteinas ⇒ Object
Devuelve el total de proteínas del plato.
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/alimento/plato.rb', line 15 def getProteinas aux = listaAlimentos.head aux2 = listaGramos.head proteinas = 0 gramosTotales = 0 while aux != nil && listaGramos != nil proteinas += aux.value.proteinas * (aux2.value/100) gramosTotales = aux2.value aux = aux.next aux2 = aux2.next end return ((proteinas * 100)/gramosTotales).round(2) end |
#getValorCaloricoTotal ⇒ Object
Devuelve el total del valor calórico del plato.
67 68 69 70 71 72 |
# File 'lib/alimento/plato.rb', line 67 def getValorCaloricoTotal proteinas = (getProteinas * getGramosTotales) / 100 carbohidratos = (getCarbohidratos * getGramosTotales) / 100 lipidos = (getLipidos * getGramosTotales) / 100 return (proteinas*4 + carbohidratos*9 + lipidos*4).round(2) end |
#to_s ⇒ Object
73 74 75 76 77 78 |
# File 'lib/alimento/plato.rb', line 73 def to_s ret = "Nombre: #{@nombre}\n" ret << listaAlimentos.to_s ret += "\n" ret end |