Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/Ein/menu.rb
Instance Attribute Summary collapse
-
#almuerzos ⇒ Object
Returns the value of attribute almuerzos.
-
#cenas ⇒ Object
Returns the value of attribute cenas.
-
#desayunos ⇒ Object
Returns the value of attribute desayunos.
-
#dia ⇒ Object
Returns the value of attribute dia.
-
#ingestas ⇒ Object
Returns the value of attribute ingestas.
-
#titulo(tit) ⇒ Object
Returns the value of attribute titulo.
Instance Method Summary collapse
- #almuerzo(alm, options = {}) ⇒ Object
- #cena(cen, options = {}) ⇒ Object
- #desayuno(des, options = {}) ⇒ Object
- #ingesta(ing, options = {}) ⇒ Object
-
#initialize(dia, &block) ⇒ Menu
constructor
A new instance of Menu.
- #to_s ⇒ Object
Constructor Details
#initialize(dia, &block) ⇒ Menu
Returns a new instance of Menu.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/Ein/menu.rb', line 6 def initialize (dia, &block) @dia = dia @titulo = nil @ingestas = [] @desayunos = [] @almuerzos = [] @cenas = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#almuerzos ⇒ Object
Returns the value of attribute almuerzos.
3 4 5 |
# File 'lib/Ein/menu.rb', line 3 def almuerzos @almuerzos end |
#cenas ⇒ Object
Returns the value of attribute cenas.
3 4 5 |
# File 'lib/Ein/menu.rb', line 3 def cenas @cenas end |
#desayunos ⇒ Object
Returns the value of attribute desayunos.
3 4 5 |
# File 'lib/Ein/menu.rb', line 3 def desayunos @desayunos end |
#dia ⇒ Object
Returns the value of attribute dia.
3 4 5 |
# File 'lib/Ein/menu.rb', line 3 def dia @dia end |
#ingestas ⇒ Object
Returns the value of attribute ingestas.
3 4 5 |
# File 'lib/Ein/menu.rb', line 3 def ingestas @ingestas end |
#titulo(tit) ⇒ Object
Returns the value of attribute titulo.
3 4 5 |
# File 'lib/Ein/menu.rb', line 3 def titulo @titulo end |
Instance Method Details
#almuerzo(alm, options = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/Ein/menu.rb', line 60 def almuerzo (alm, = {}) almuerzo = alm almuerzo << "(#{[:descripcion]})" if [:descripcion] almuerzo << "(#{[:porcion]})" if [:porcion] almuerzo << "(#{[:gramos]})" if [:gramos] almuerzo << "(#{[:grasas]})" if [:grasas] almuerzo << "(#{[:carbohidratos]})" if [:carbohidratos] almuerzo << "(#{[:proteinas]})" if [:proteinas] almuerzo << "(#{[:fibra]})" if [:fibra] almuerzo << "(#{[:sal]})" if [:sal] @almuerzos << almuerzo end |
#cena(cen, options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/Ein/menu.rb', line 78 def cena (cen, = {}) cena = cen cena << "(#{[:descripcion]})" if [:descripcion] cena << "(#{[:porcion]})" if [:porcion] cena << "(#{[:gramos]})" if [:gramos] cena << "(#{[:grasas]})" if [:grasas] cena << "(#{[:carbohidratos]})" if [:carbohidratos] cena << "(#{[:proteinas]})" if [:proteinas] cena << "(#{[:fibra]})" if [:fibra] cena << "(#{[:sal]})" if [:sal] @cenas << cena end |
#desayuno(des, options = {}) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/Ein/menu.rb', line 43 def desayuno (des, = {}) desayuno = des desyuno << "(#{[:descripcion]})" if [:descripcion] desyuno << "(#{[:porcion]})" if [:porcion] desyuno << "(#{[:gramos]})" if [:gramos] desyuno << "(#{[:grasas]})" if [:grasas] desyuno << "(#{[:carbohidratos]})" if [:carbohidratos] desyuno << "(#{[:proteinas]})" if [:proteinas] desyuno << "(#{[:fibra]})" if [:fibra] desyuno << "(#{[:sal]})" if [:sal] @desayunos << desayuno end |
#ingesta(ing, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/Ein/menu.rb', line 32 def ingesta(ing, = {}) ingesta = ing ingesta << "(#{[:min]})" if [:min] ingesta << "(#{[:max]})" if [:max] @ingestas << ingesta end |
#to_s ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/Ein/menu.rb', line 99 def to_s #aqui tienes q cambiarlo por esto #output = "\n #{@dia}" porq si no no te imprime el dia estaras escachando las cosas @valor_total = 0 output = "\n#{@titulo}\n" output << "#{@dia} \t\t Composición nutricional \n" output << "========================================================\n" output << "\t\t\tGrasas Carbohidratos Proteínas Fibra Sal Valor energético\n" output << "Desayuno\n" @desayunos.each do |desayuno| if desayuno[:descripcion] == nil desayuno[:descripcion] = "--" end if desayuno[:grasas] == nil desayuno[:grasas] = 0.0 end if desayuno[:carbohidratos] == nil desayuno[:carbohidratos] = 0.0 end if desayuno[:proteinas] == nil desayuno[:proteinas] = 0.0 end if desayuno[:fibra] == nil desayuno[:fibra] = 0.0 end if desayuno[:sal] == nil desayuno[:sal] = 0.0 end output << "#{desayuno[:descripcion]}\t" output << "#{desayuno[:grasas]} " output << "\t #{desayuno[:carbohidratos]} " output << "\t#{desayuno[:proteinas]} " output << "\t #{desayuno[:fibra]} " output << "\t#{desayuno[:sal]} " output << "\t#{@valor_e_kc_d = ((4.0 * desayuno[:carbohidratos]) + (4.0 * desayuno[:proteinas]) + (9.0 * desayuno[:grasas]) + (6.0 * desayuno[:sal])).round(2)}\n" @valor_total += @valor_e_kc_d end output << "\n\nAlmuerzo\n" @almuerzos.each do |almuerzo| if almuerzo[:descripcion] == nil almuerzo[:descripcion] = "--" end if almuerzo[:grasas] == nil almuerzo[:grasas] = 0.0 end if almuerzo[:carbohidratos] == nil almuerzo[:carbohidratos] = 0.0 end if almuerzo[:proteinas] == nil almuerzo[:proteinas] = 0.0 end if almuerzo[:fibra] == nil almuerzo[:fibra] = 0.0 end if almuerzo[:sal] == nil almuerzo[:sal] = 0.0 end output << "\n#{almuerzo[:descripcion]} " output << " \t\t #{almuerzo[:grasas]} " output << "\t #{almuerzo[:carbohidratos]} " output << "\t#{almuerzo[:proteinas]} " output << "\t #{almuerzo[:fibra]} " output << "\t#{almuerzo[:sal]} " output << "\t#{@valor_e_kc_a = ((4.0 * almuerzo[:carbohidratos]) + (4.0 * almuerzo[:proteinas]) + (9.0 * almuerzo[:grasas]) + (6.0 * almuerzo[:sal])).round(2)}" @valor_total += @valor_e_kc_a end output << "\n\nCena\n" @cenas.each do |cena| if cena[:descripcion] == nil cena[:descripcion] = "--" end if cena[:grasas] == nil cena[:grasas] = 0.0 end if cena[:carbohidratos] == nil cena[:carbohidratos] = 0.0 end if cena[:proteinas] == nil cena[:proteinas] = 0.0 end if cena[:fibra] == nil cena[:fibra] = 0.0 end if cena[:sal] == nil cena[:sal] = 0.0 end output << "\n#{cena[:descripcion]} " output << " #{cena[:grasas]} " output << "\t #{cena[:carbohidratos]} " output << "\t#{cena[:proteinas]} " output << "\t #{cena[:fibra]} " output << "\t#{cena[:sal]} " output << "\t#{@valor_e_kc_c = ((4.0 * cena[:carbohidratos]) + (4.0 * cena[:proteinas]) + (9.0 * cena[:grasas]) + (6.0 * cena[:sal])).round(2)}" @valor_total += @valor_e_kc_c #Tienes q devolver la variable end output << "\nValor energético total" output << "\t#{@valor_total}" output end |