Class: Alimento::PlatoDSL
- Inherits:
-
Object
- Object
- Alimento::PlatoDSL
- Includes:
- Comparable
- Defined in:
- lib/alimento/plato_dsl.rb
Overview
Plato formado por cantidades de uno o más alimentos.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #alimento(alimento, options = {}) ⇒ Object
-
#getCarbohidratos ⇒ Object
Devuelve el total de carbohidratos del plato.
-
#getEmisionGEI ⇒ Object
Devuelve las emisiones de gases de efecto invernadero de un 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.
-
#getTerreno ⇒ Object
Devuelve el terreno consumido por los alimentos de un plato.
-
#getValorCaloricoTotal ⇒ Object
Devuelve el total del valor calórico del plato.
-
#initialize(name, &block) ⇒ PlatoDSL
constructor
A new instance of PlatoDSL.
- #nombre(name) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ PlatoDSL
Returns a new instance of PlatoDSL.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/alimento/plato_dsl.rb', line 9 def initialize(name, &block) @name = name @listaAlimentos = List.new() @listaGramos = List.new() if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/alimento/plato_dsl.rb', line 8 def name @name end |
Instance Method Details
#<=>(other) ⇒ Object
122 123 124 125 126 |
# File 'lib/alimento/plato_dsl.rb', line 122 def <=>(other) if other != nil getValorCaloricoTotal <=> other.getValorCaloricoTotal end end |
#alimento(alimento, options = {}) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/alimento/plato_dsl.rb', line 25 def alimento(alimento, = {}) unless [:gramos].nil? @listaAlimentos << alimento @listaGramos << [:gramos] end end |
#getCarbohidratos ⇒ Object
Devuelve el total de carbohidratos del plato.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/alimento/plato_dsl.rb', line 60 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 |
#getEmisionGEI ⇒ Object
Devuelve las emisiones de gases de efecto invernadero de un plato.
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/alimento/plato_dsl.rb', line 91 def getEmisionGEI aux = @listaAlimentos.head aux2 = @listaGramos.head geiTotal = 0 while aux != nil && aux2 != nil geiTotal += aux.value.GEI * (aux2.value / 100) aux = aux.next aux2 = aux2.next end geiTotal.round(2) end |
#getGramosTotales ⇒ Object
Devuelve la cantidad total de gramos del plato.
74 75 76 77 78 79 80 81 82 |
# File 'lib/alimento/plato_dsl.rb', line 74 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/alimento/plato_dsl.rb', line 46 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/alimento/plato_dsl.rb', line 32 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 |
#getTerreno ⇒ Object
Devuelve el terreno consumido por los alimentos de un plato.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/alimento/plato_dsl.rb', line 105 def getTerreno aux = @listaAlimentos.head aux2 = @listaGramos.head terrenoTotal = 0 while aux != nil && aux2 != nil terrenoTotal = aux.value.terreno * (aux2.value / 100) aux = aux.next end terrenoTotal.round(2) end |
#getValorCaloricoTotal ⇒ Object
Devuelve el total del valor calórico del plato.
84 85 86 87 88 89 |
# File 'lib/alimento/plato_dsl.rb', line 84 def getValorCaloricoTotal proteinas = (getProteinas * getGramosTotales) / 100 carbohidratos = (getCarbohidratos * getGramosTotales) / 100 lipidos = (getLipidos * getGramosTotales) / 100 return (proteinas*4 + carbohidratos*9 + lipidos*4).round(2) end |
#nombre(name) ⇒ Object
22 23 24 |
# File 'lib/alimento/plato_dsl.rb', line 22 def nombre(name) @name = name end |
#to_s ⇒ Object
116 117 118 119 120 121 |
# File 'lib/alimento/plato_dsl.rb', line 116 def to_s ret = "#{@name}\n" ret + @listaAlimentos.zip(@listaGramos).map { |x| x.first.to_s + " - " + x.last.to_s + " gramos" }.join("\n") end |