Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/prct06/menu.rb
Instance Attribute Summary collapse
-
#descripcion ⇒ Object
Returns the value of attribute descripcion.
-
#dia ⇒ Object
Returns the value of attribute dia.
-
#ingesta(ing, options = {}) ⇒ Object
Returns the value of attribute ingesta.
-
#nombre ⇒ Object
Returns the value of attribute nombre.
Instance Method Summary collapse
- #almuerzo(al, options = {}) ⇒ Object
- #cena(ce, options = {}) ⇒ Object
- #desayuno(des, options = {}) ⇒ Object
-
#initialize(dia, &block) ⇒ Menu
constructor
A new instance of Menu.
- #titulo(nom) ⇒ Object
- #to_s ⇒ Object
- #valor_energetico(comida) ⇒ Object
Constructor Details
#initialize(dia, &block) ⇒ Menu
Returns a new instance of Menu.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/prct06/menu.rb', line 4 def initialize(dia,&block) @dia = dia @ingesta = [] @desayuno = [] @cena = [] @almuerzo = [] if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#descripcion ⇒ Object
Returns the value of attribute descripcion.
2 3 4 |
# File 'lib/prct06/menu.rb', line 2 def descripcion @descripcion end |
#dia ⇒ Object
Returns the value of attribute dia.
2 3 4 |
# File 'lib/prct06/menu.rb', line 2 def dia @dia end |
#ingesta(ing, options = {}) ⇒ Object
Returns the value of attribute ingesta.
2 3 4 |
# File 'lib/prct06/menu.rb', line 2 def ingesta @ingesta end |
#nombre ⇒ Object
Returns the value of attribute nombre.
2 3 4 |
# File 'lib/prct06/menu.rb', line 2 def nombre @nombre end |
Instance Method Details
#almuerzo(al, options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/prct06/menu.rb', line 105 def almuerzo(al, = {}) lunch = al lunch << "(#{[:descripcion]})" if [:descripcion] lunch << "(#{[:porcion]})" if [:porcion] lunch << "(#{[:gramos]})" if [:gramos] lunch << "(#{[:grasas]})" if [:grasas] lunch << "(#{[:carbohidratos]})" if [:carbohidratos] lunch << "(#{[:proteinas]})" if [:proteinas] lunch << "(#{[:fibra]})" if [:fibra] lunch << "(#{[:sal]})" if [:sal] @almuerzo << lunch end |
#cena(ce, options = {}) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/prct06/menu.rb', line 119 def cena(ce, = {}) din = ce din << "(#{[:descripcion]})" if [:descripcion] din << "(#{[:porcion]})" if [:porcion] din << "(#{[:gramos]})" if [:gramos] din << "(#{[:grasas]})" if [:grasas] din << "(#{[:carbohidratos]})" if [:carbohidratos] din << "(#{[:proteinas]})" if [:proteinas] din << "(#{[:fibra]})" if [:fibra] din << "(#{[:sal]})" if [:sal] @cena << din end |
#desayuno(des, options = {}) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/prct06/menu.rb', line 91 def desayuno(des, = {}) bf = des bf << "(#{[:descripcion]})" if [:descripcion] bf << "(#{[:porcion]})" if [:porcion] bf << "(#{[:gramos]})" if [:gramos] bf << "(#{[:grasas]})" if [:grasas] bf << "(#{[:carbohidratos]})" if [:carbohidratos] bf << "(#{[:proteinas]})" if [:proteinas] bf << "(#{[:fibra]})" if [:fibra] bf << "(#{[:sal]})" if [:sal] @desayuno << bf end |
#titulo(nom) ⇒ Object
79 80 81 |
# File 'lib/prct06/menu.rb', line 79 def titulo(nom) nombr = nom end |
#to_s ⇒ Object
20 21 22 23 24 25 26 27 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 |
# File 'lib/prct06/menu.rb', line 20 def to_s vet = 0 output = @dia output << " Composición Nutricional\n" output << "===========================================================\n" output << " grasas carbohidratos proteínas fibra sal valor energético\n" output << "Desayuno\n" @desayuno.each do |alimento| vet += valor_energetico(alimento) output << "*#{alimento[:descripcion]}* " output << "#{alimento[:grasas]} " output << "#{alimento[:carbohidratos]} " output << "#{alimento[:proteinas]} " output << "#{alimento[:fibra]} " output << "#{alimento[:sal]} " output << "#{valor_energetico(alimento)}\n" end output << "\nAlmuerzo\n" @almuerzo.each do |alimento| vet += valor_energetico(alimento) output << "*#{alimento[:descripcion]}* " output << "#{alimento[:grasas]} " output << "#{alimento[:carbohidratos]} " output << "#{alimento[:proteinas]} " output << "#{alimento[:fibra]} " output << "#{alimento[:sal]} " output << "#{valor_energetico(alimento)}\n" end output << "\nCena\n" @cena.each do |alimento| vet += valor_energetico(alimento) output << "*#{alimento[:descripcion]}* " output << "#{alimento[:grasas]} " output << "#{alimento[:carbohidratos]} " output << "#{alimento[:proteinas]} " output << "#{alimento[:fibra]} " output << "#{alimento[:sal]} " output << "#{valor_energetico(alimento)}\n" end output << "Valor energético total " output << "#{vet}" output end |
#valor_energetico(comida) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/prct06/menu.rb', line 72 def valor_energetico(comida) kcal = comida[:grasas] * 0.9 kcal += comida[:carbohidratos] * 0.4 kcal += comida[:proteinas] * 0.4 kcal.round(2) end |