Class: Plato
- Inherits:
-
Object
- Object
- Plato
- Defined in:
- lib/food/plato.rb
Constant Summary collapse
- @@list =
Lista.new(nil,nil)
- @@equivalencias =
{ "cucharadas"=>2,"piezas pequeñas"=>5,"taza"=>5,"cucharón"=>4,"pieza"=>8,"cucharada"=>2 }
Instance Attribute Summary collapse
-
#aceites ⇒ Object
readonly
Returns the value of attribute aceites.
-
#cereales ⇒ Object
readonly
Returns the value of attribute cereales.
-
#frutas ⇒ Object
readonly
Returns the value of attribute frutas.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
-
#proteinas ⇒ Object
readonly
Returns the value of attribute proteinas.
-
#valor_energetico ⇒ Object
readonly
Returns the value of attribute valor_energetico.
-
#vegetales ⇒ Object
readonly
Returns the value of attribute vegetales.
Instance Method Summary collapse
- #aceite(n_alimento, options = {}) ⇒ Object
- #cereal(n_alimento, options = {}) ⇒ Object
- #fruta(n_alimento, options = {}) ⇒ Object
- #get_cantidad(porcion) ⇒ Object
-
#initialize(nombre, &block) ⇒ Plato
constructor
A new instance of Plato.
- #proteina(n_alimento, options = {}) ⇒ Object
- #to_s ⇒ Object
- #vegetal(n_alimento, options = {}) ⇒ Object
Constructor Details
#initialize(nombre, &block) ⇒ Plato
Returns a new instance of Plato.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/food/plato.rb', line 32 def initialize nombre, &block @nombre = nombre @valor_energetico = 0 @vegetales = [] @cereales = [] @frutas = [] @proteinas = [] @aceites = [] if (block != nil) instance_eval(&block) end end |
Instance Attribute Details
#aceites ⇒ Object (readonly)
Returns the value of attribute aceites.
4 5 6 |
# File 'lib/food/plato.rb', line 4 def aceites @aceites end |
#cereales ⇒ Object (readonly)
Returns the value of attribute cereales.
4 5 6 |
# File 'lib/food/plato.rb', line 4 def cereales @cereales end |
#frutas ⇒ Object (readonly)
Returns the value of attribute frutas.
4 5 6 |
# File 'lib/food/plato.rb', line 4 def frutas @frutas end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
4 5 6 |
# File 'lib/food/plato.rb', line 4 def nombre @nombre end |
#proteinas ⇒ Object (readonly)
Returns the value of attribute proteinas.
4 5 6 |
# File 'lib/food/plato.rb', line 4 def proteinas @proteinas end |
#valor_energetico ⇒ Object (readonly)
Returns the value of attribute valor_energetico.
4 5 6 |
# File 'lib/food/plato.rb', line 4 def valor_energetico @valor_energetico end |
#vegetales ⇒ Object (readonly)
Returns the value of attribute vegetales.
4 5 6 |
# File 'lib/food/plato.rb', line 4 def vegetales @vegetales end |
Instance Method Details
#aceite(n_alimento, options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/food/plato.rb', line 105 def aceite n_alimento, = {} cantidad = 0 alimento = @@list.detect { |x| n_alimento == x.nombre } if [:gramos] cantidad = [:gramos] elsif [:porcion] cantidad = get_cantidad [:porcion] end @valor_energetico += cantidad*alimento.valor_energetico @aceites.push([alimento, (cantidad*alimento.valor_energetico).round(3)]) end |
#cereal(n_alimento, options = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/food/plato.rb', line 69 def cereal n_alimento, = {} cantidad = 0 alimento = @@list.detect { |x| n_alimento == x.nombre } if [:gramos] cantidad = [:gramos] elsif [:porcion] cantidad = get_cantidad [:porcion] end @valor_energetico += cantidad*alimento.valor_energetico @cereales.push([alimento, (cantidad*alimento.valor_energetico).round(3)]) end |
#fruta(n_alimento, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/food/plato.rb', line 81 def fruta n_alimento, = {} cantidad = 0 alimento = @@list.detect { |x| n_alimento == x.nombre } if [:gramos] cantidad = [:gramos] elsif [:porcion] cantidad = get_cantidad [:porcion] end @valor_energetico += cantidad*alimento.valor_energetico @frutas.push([alimento, (cantidad*alimento.valor_energetico).round(3)]) end |
#get_cantidad(porcion) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/food/plato.rb', line 47 def get_cantidad porcion numero = porcion.split[0].to_r cadena = "" porcion.split[1..cadena.length-1].each do |x| cadena += x + " " end cantidad = numero * @@equivalencias[cadena.chomp ' '] end |
#proteina(n_alimento, options = {}) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/food/plato.rb', line 93 def proteina n_alimento, = {} cantidad = 0 alimento = @@list.detect { |x| n_alimento == x.nombre } if [:gramos] cantidad = [:gramos] elsif [:porcion] cantidad = get_cantidad [:porcion] end @valor_energetico += cantidad*alimento.valor_energetico @proteinas.push([alimento, (cantidad*alimento.valor_energetico).round(3)]) end |
#to_s ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/food/plato.rb', line 117 def to_s cadena = @nombre + "\n" cadena += "\nComposición nutricional: \n" for i in 0..@vegetales.length-1 do cadena += "%-70s\t%s\n" % [@vegetales[i][0].to_s, @vegetales[i][1].to_s] end for i in 0..@frutas.length-1 do cadena += "%-70s\t%s\n" % [@frutas[i][0].to_s, @frutas[i][1].to_s] end for i in 0..@cereales.length-1 do cadena += "%-70s\t%s\n" % [@cereales[i][0].to_s, @cereales[i][1].to_s] end for i in 0..@aceites.length-1 do cadena += "%-70s\t%s\n" % [@aceites[i][0].to_s, @aceites[i][1].to_s] end for i in 0..@proteinas.length-1 do cadena += "%-70s\t%s\n" % [@proteinas[i][0].to_s, @proteinas[i][1].to_s] end cadena+= "Valor energético:\t" + @valor_energetico.round(3).to_s + "\n" cadena end |
#vegetal(n_alimento, options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/food/plato.rb', line 57 def vegetal n_alimento, = {} cantidad = 0 alimento = @@list.detect { |x| n_alimento == x.nombre } if [:gramos] cantidad = [:gramos] elsif [:porcion] cantidad = get_cantidad [:porcion] end @valor_energetico += cantidad*alimento.valor_energetico @vegetales.push([alimento, (cantidad*alimento.valor_energetico).round(3)]) end |