Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/Menu.rb
Instance Attribute Summary collapse
-
#cenas ⇒ Object
Returns the value of attribute cenas.
-
#comidas ⇒ Object
Returns the value of attribute comidas.
-
#desayunos ⇒ Object
Returns the value of attribute desayunos.
-
#dia ⇒ Object
Returns the value of attribute dia.
-
#tiempo_comida ⇒ Object
Returns the value of attribute tiempo_comida.
-
#titulo_menu ⇒ Object
Returns the value of attribute titulo_menu.
-
#val_ener ⇒ Object
Returns the value of attribute val_ener.
-
#vet ⇒ Object
Returns the value of attribute vet.
Instance Method Summary collapse
- #cena(options = {}) ⇒ Object
- #comida(options = {}) ⇒ Object
- #desayuno(options = {}) ⇒ Object
- #ingesta(options = {}) ⇒ Object
-
#initialize(dia, &block) ⇒ Menu
constructor
A new instance of Menu.
- #printm ⇒ Object
- #titulo(nombre) ⇒ Object
- #to_s ⇒ Object
- #valor_energetico(grasas, carbohidratos, proteinas, fibra, sal) ⇒ Object
Constructor Details
#initialize(dia, &block) ⇒ Menu
Returns a new instance of Menu.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/Menu.rb', line 5 def initialize(dia, &block) @dia = dia @titulo_menu = nil @tiempo_comida = [] @desayunos = [] @comidas = [] @cenas = [] @val_ener = nil @vet = 0 if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#cenas ⇒ Object
Returns the value of attribute cenas.
3 4 5 |
# File 'lib/Menu.rb', line 3 def cenas @cenas end |
#comidas ⇒ Object
Returns the value of attribute comidas.
3 4 5 |
# File 'lib/Menu.rb', line 3 def comidas @comidas end |
#desayunos ⇒ Object
Returns the value of attribute desayunos.
3 4 5 |
# File 'lib/Menu.rb', line 3 def desayunos @desayunos end |
#dia ⇒ Object
Returns the value of attribute dia.
3 4 5 |
# File 'lib/Menu.rb', line 3 def dia @dia end |
#tiempo_comida ⇒ Object
Returns the value of attribute tiempo_comida.
3 4 5 |
# File 'lib/Menu.rb', line 3 def tiempo_comida @tiempo_comida end |
#titulo_menu ⇒ Object
Returns the value of attribute titulo_menu.
3 4 5 |
# File 'lib/Menu.rb', line 3 def @titulo_menu end |
#val_ener ⇒ Object
Returns the value of attribute val_ener.
3 4 5 |
# File 'lib/Menu.rb', line 3 def val_ener @val_ener end |
#vet ⇒ Object
Returns the value of attribute vet.
3 4 5 |
# File 'lib/Menu.rb', line 3 def vet @vet end |
Instance Method Details
#cena(options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/Menu.rb', line 78 def cena( = {}) dinner = sprintf(" %-25s", "\"#{[:descripcion]}\"") dinner << sprintf(" %-15s", "#{[:porcion]}") dinner << sprintf(" %-10s", "#{[:gramos]}") dinner << sprintf(" %-10s", "#{[:grasas]}") dinner << sprintf(" %-15s", "#{[:carbohidratos]}") dinner << sprintf(" %-12s", "#{[:proteinas]}") dinner << sprintf(" %-8s", " #{[:fibra]}") dinner << sprintf(" %-7s", "#{[:sal]}") valor_energetico([:grasas], [:carbohidratos], [:proteinas], [:fibra], [:sal]) dinner << sprintf(" %-10s", "#{@val_ener}") @cenas << dinner end |
#comida(options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/Menu.rb', line 62 def comida( = {}) meal = sprintf(" %-25s", "\"#{[:descripcion]}\"") meal << sprintf(" %-15s", "#{[:porcion]}") meal << sprintf(" %-10s", "#{[:gramos]}") meal << sprintf(" %-10s", "#{[:grasas]}") meal << sprintf(" %-15s", "#{[:carbohidratos]}") meal << sprintf(" %-12s", "#{[:proteinas]}") meal << sprintf(" %-8s", " #{[:fibra]}") meal << sprintf(" %-7s", "#{[:sal]}") valor_energetico([:grasas], [:carbohidratos], [:proteinas], [:fibra], [:sal]) meal << sprintf(" %-10s", "#{@val_ener}") @comidas << meal end |
#desayuno(options = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/Menu.rb', line 46 def desayuno( = {}) breakfast = sprintf(" %-25s", "\"#{[:descripcion]}\"") breakfast << sprintf(" %-15s", "#{[:porcion]}") breakfast << sprintf(" %-10s", "#{[:gramos]}") breakfast << sprintf(" %-10s", "#{[:grasas]}") breakfast << sprintf(" %-15s", "#{[:carbohidratos]}") breakfast << sprintf(" %-12s", "#{[:proteinas]}") breakfast << sprintf(" %-8s", " #{[:fibra]}") breakfast << sprintf(" %-7s", "#{[:sal]}") valor_energetico([:grasas], [:carbohidratos], [:proteinas], [:fibra], [:sal]) breakfast << sprintf(" %-10s", "#{@val_ener}") @desayunos << breakfast end |
#ingesta(options = {}) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/Menu.rb', line 39 def ingesta( = {}) time = " #{[:min]}" if [:min] time << " #{[:max]}" if [:max] @tiempo_comida << time end |
#printm ⇒ Object
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 |
# File 'lib/Menu.rb', line 122 def printm cout = "\n" + @dia + " " + @titulo_menu + " Composicion nutricional" cout << "\n#{'=' * cout.size}\n" header=sprintf("%34s %14s %10s %17s %12s %7s %6s %20s\n","porcion", "gramos", "grasas", "carbohidratos", "proteinas", "fibra", "sal", "valor energetico") cout << header cout << "Desayuno\n" @desayunos.each do |aux| cout << "#{aux}\n" end cout << "\ncomida\n" @comidas.each do |aux2| cout << "#{aux2}\n" end cout << "\ncena\n" @cenas.each do |aux3| cout << "#{aux3}\n" end cout << "\nvalor energetico total #{@vet.round(2)}" + "\n" puts cout end |
#titulo(nombre) ⇒ Object
24 25 26 |
# File 'lib/Menu.rb', line 24 def titulo(nombre) @titulo_menu = nombre end |
#to_s ⇒ Object
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 |
# File 'lib/Menu.rb', line 94 def to_s cout = "\n" + @dia + " " + @titulo_menu + " Composicion nutricional" cout << "\n#{'=' * cout.size}\n" header=sprintf("%34s %14s %10s %17s %12s %7s %6s %20s\n","porcion", "gramos", "grasas", "carbohidratos", "proteinas", "fibra", "sal", "valor energetico") cout << header cout << "Desayuno\n" @desayunos.each do |aux| cout << "#{aux}\n" end cout << "\ncomida\n" @comidas.each do |aux2| cout << "#{aux2}\n" end cout << "\ncena\n" @cenas.each do |aux3| cout << "#{aux3}\n" end cout << "\nvalor energetico total #{@vet.round(2)}" + "\n" cout end |
#valor_energetico(grasas, carbohidratos, proteinas, fibra, sal) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/Menu.rb', line 28 def valor_energetico(grasas, carbohidratos, proteinas, fibra, sal) if grasas == nil then grasas = 0 end if carbohidratos == nil then carbohidratos = 0 end if proteinas == nil then proteinas = 0 end if fibra == nil then fibra = 0 end if sal == nil then sal = 0 end @val_ener = (grasas * 9) + (carbohidratos * 4) + (proteinas * 4) + (fibra * 4) + (sal * 6) @vet += @val_ener end |