Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/prct06/menu.rb
Instance Attribute Summary collapse
-
#ingredients ⇒ Object
Returns the value of attribute ingredients.
-
#instructions ⇒ Object
Returns the value of attribute instructions.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #almuerzo(name, options = {}) ⇒ Object
- #cena(name, options = {}) ⇒ Object
- #desayuno(name, options = {}) ⇒ Object
- #ingesta(name, options = {}) ⇒ Object
-
#initialize(name, &block) ⇒ Menu
constructor
A new instance of Menu.
- #titulo(name) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &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 24 25 |
# File 'lib/prct06/menu.rb', line 6 def initialize(name, &block) @desayuno_array = [] @almuerzo = [] @cena = [] @titulo @ingesta = [] @name = name @ingredients = [] @instructions = [] @valor_energetico = 0 if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#ingredients ⇒ Object
Returns the value of attribute ingredients.
4 5 6 |
# File 'lib/prct06/menu.rb', line 4 def ingredients @ingredients end |
#instructions ⇒ Object
Returns the value of attribute instructions.
4 5 6 |
# File 'lib/prct06/menu.rb', line 4 def instructions @instructions end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/prct06/menu.rb', line 4 def name @name end |
Instance Method Details
#almuerzo(name, options = {}) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/prct06/menu.rb', line 194 def almuerzo(name, = {}) almuerzo = name almuerzo << "(#{[:descripcion]}" if [:descripcion] almuerzo << "(#{[:porcion]}" if [:porcion] almuerzo << "(#{[:grasas]}" if [:grasas] almuerzo << "(#{[:carbohidratos]}" if [:carbohidratos] almuerzo << "(#{[:proteinas]}" if [:proteinas] almuerzo << "(#{[:fibra]}" if [:fibra] almuerzo << "(#{[:sal]}" if [:sal] @almuerzo << almuerzo end |
#cena(name, options = {}) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/prct06/menu.rb', line 208 def cena(name, = {}) cena = name cena << "(#{[:descripcion]}" if [:descripcion] cena << "(#{[:porcion]}" if [:porcion] cena << "(#{[:gramo]}" if [:gramo] cena << "(#{[:grasa]}" if [:grasa] cena << "(#{[:proteina]}" if [:proteina] cena << "(#{[:carbohidratos]}" if [:carbohidratos] cena << "(#{[:sal]}" if [:sal] @cena << cena end |
#desayuno(name, options = {}) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/prct06/menu.rb', line 176 def desayuno(name, = {}) desayuno = name desayuno << "(#{[:descripcion]}" if [:descripcion] desayuno << "(#{[:porcion]}" if [:porcion] desayuno << "(#{[:grasas]}" if [:grasas] desayuno << "(#{[:gramos]}" if [:gramos] desayuno << "(#{[:carbohidratos]}" if [:carbohidratos] desayuno << "(#{[:proteinas]}" if [:proteinas] desayuno << "(#{[:fibra]}" if [:fibra] desayuno << "(#{[:sal]}" if [:sal] @desayuno_array << desayuno end |
#ingesta(name, options = {}) ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/prct06/menu.rb', line 167 def ingesta(name, = {}) ingesta = name ingesta << "(#{[:min]}" if [:min] ingesta << "(#{[:max]}" if [:max] @ingesta << ingesta end |
#titulo(name) ⇒ Object
162 163 164 |
# File 'lib/prct06/menu.rb', line 162 def titulo(name) @titulo = name end |
#to_s ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 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 |
# File 'lib/prct06/menu.rb', line 28 def to_s puts @name puts "\t \t \t Composición nutricional" puts "\n#{'=' *100}\n\n" puts "\t \t \t Grasa \t Carbohidratos \t Proteinas \t fibra \t sal \t valor energético \n \n " @valor_total = 0 @desayuno_array.each do |elemento| if elemento[:descripcion] == nil elemento[:descripcion] = 0.00 end if elemento[:fibra] == nil elemento[:fibra] = 0.00 end if elemento[:grasas] == nil elemento[:grasas] = 0.00 end if elemento[:carbohidratos] == nil elemento[:carbohidratos] = 0.00 end if elemento[:proteinas] == nil elemento[:proteinas] = 0.00 end if elemento[:sal] == nil elemento[:sal] = 0.00 end print elemento[:descripcion] print "\t #{elemento[:grasas]}" print "\t #{elemento[:carbohidratos]}" print "\t \t #{elemento[:proteinas]}" print "\t \t #{elemento[:fibra]}" print "\t #{elemento[:sal]}" print "\t #{@valor_energetico = (elemento[:grasas]*9 + elemento[:carbohidratos]*4 + elemento[:proteinas]*4 +elemento[:fibra]*2 + elemento[:sal]*6)/10}" puts @valor_total += @valor_energetico end @almuerzo.each do |elemento| if elemento[:descripcion] == nil elemento[:descripcion] = 0.00 end if elemento[:fibra] == nil elemento[:fibra] = 0.00 end if elemento[:grasas] == nil elemento[:grasas] = 0.00 end if elemento[:carbohidratos] == nil elemento[:carbohidratos] = 0.00 end if elemento[:proteinas] == nil elemento[:proteinas] = 0.00 end if elemento[:sal] == nil elemento[:sal] = 0.00 end print "#{elemento[:descripcion]}" print "\t \t #{elemento[:grasas]}" print "\t #{elemento[:carbohidratos]}" print "\t \t#{elemento[:proteinas]}" print "\t \t#{elemento[:fibra]}" print "\t #{elemento[:sal]}" print "\t #{@valor_energetico = (elemento[:grasas]*9 + elemento[:carbohidratos]*4 + elemento[:proteinas]*4 +elemento[:fibra]*2 + elemento[:sal]*6)/10}" puts @valor_total += @valor_energetico end @cena.each do |elemento| if elemento[:descripcion] == nil elemento[:descripcion] = 0.00 end if elemento[:fibra] == nil elemento[:fibra] = 0.00 end if elemento[:grasas] == nil elemento[:grasas] = 0.00 end if elemento[:carbohidratos] == nil elemento[:carbohidratos] = 0.00 end if elemento[:proteinas] == nil elemento[:proteinas] = 0.00 end if elemento[:sal] == nil elemento[:sal] = 0.00 end print elemento[:descripcion] print " \t #{elemento[:grasas]}" print " \t #{elemento[:carbohidratos]}" print "\t \t #{elemento[:proteinas]}" print "\t \t #{elemento[:fibra]}" print "\t #{elemento[:sal]}" print " \t #{@valor_energetico = (elemento[:grasas]*9 + elemento[:carbohidratos]*4 + elemento[:proteinas]*4 +elemento[:fibra]*2 + elemento[:sal]*6)/10}" puts @valor_total += @valor_energetico end print "Valor energético total #{@valor_total}" puts puts puts puts puts puts "\n#{'=' *100}\n\n" end |