Class: Menu
- Inherits:
-
Object
- Object
- Menu
- Defined in:
- lib/pract6/Alimento.rb
Instance Attribute Summary collapse
-
#cere ⇒ Object
Returns the value of attribute cere.
-
#fru ⇒ Object
Returns the value of attribute fru.
-
#grasas ⇒ Object
Returns the value of attribute grasas.
-
#name ⇒ Object
Returns the value of attribute name.
-
#protes ⇒ Object
Returns the value of attribute protes.
-
#vege ⇒ Object
Returns the value of attribute vege.
Instance Method Summary collapse
- #aceite(alimento, cantidad) ⇒ Object
- #cereal(alimento, cantidad) ⇒ Object
- #fruta(alimento, cantidad) ⇒ Object
-
#initialize(name, &block) ⇒ Menu
constructor
A new instance of Menu.
- #proteina(alimento, cantidad) ⇒ Object
- #to_s ⇒ Object
- #vegetal(alimento, cantidad) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Menu
Returns a new instance of Menu.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/pract6/Alimento.rb', line 97 def initialize(name, &block) @name = name @calorias_total = 0 @vege = {} @fru = {} @cere = {} @protes = {} @grasa = {} @cambio = {'1 cuchara' => 50, '1 cucharon' => 150, '1 pieza' => 100, '1 taza' => 200, '1 cucharadita' => 10, '1/2 cucharada' => 50, '1/2 cucharon' => 75, '1/2 pieza' => 25, '2 piezas' => 200, '1/2 taza' => 150, '1/2 cucharadita' => 5} if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#cere ⇒ Object
Returns the value of attribute cere.
95 96 97 |
# File 'lib/pract6/Alimento.rb', line 95 def cere @cere end |
#fru ⇒ Object
Returns the value of attribute fru.
95 96 97 |
# File 'lib/pract6/Alimento.rb', line 95 def fru @fru end |
#grasas ⇒ Object
Returns the value of attribute grasas.
95 96 97 |
# File 'lib/pract6/Alimento.rb', line 95 def grasas @grasas end |
#name ⇒ Object
Returns the value of attribute name.
95 96 97 |
# File 'lib/pract6/Alimento.rb', line 95 def name @name end |
#protes ⇒ Object
Returns the value of attribute protes.
95 96 97 |
# File 'lib/pract6/Alimento.rb', line 95 def protes @protes end |
#vege ⇒ Object
Returns the value of attribute vege.
95 96 97 |
# File 'lib/pract6/Alimento.rb', line 95 def vege @vege end |
Instance Method Details
#aceite(alimento, cantidad) ⇒ Object
143 144 145 146 |
# File 'lib/pract6/Alimento.rb', line 143 def aceite(alimento, cantidad) @grasa[alimento] = @cambio[cantidad] end |
#cereal(alimento, cantidad) ⇒ Object
138 139 140 141 |
# File 'lib/pract6/Alimento.rb', line 138 def cereal(alimento, cantidad) @cere[alimento] = @cambio[cantidad] end |
#fruta(alimento, cantidad) ⇒ Object
127 128 129 130 131 |
# File 'lib/pract6/Alimento.rb', line 127 def fruta(alimento, cantidad) @fru[alimento] = @cambio[cantidad] end |
#proteina(alimento, cantidad) ⇒ Object
133 134 135 136 |
# File 'lib/pract6/Alimento.rb', line 133 def proteina(alimento, cantidad) @protes[alimento] = @cambio[cantidad] end |
#to_s ⇒ Object
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 |
# File 'lib/pract6/Alimento.rb', line 148 def to_s ouputs = @name ouputs << "\n" ouputs << "#{'=' * @name.size}\n\n" ouputs << "Nombre Proteinas Grasas Hidratos Valor energético\n" @vege.each do |key,value| ouputs <<"#{key}\t #{key.calorias*value/100}" @calorias_total = @calorias_total + key.calorias*value/100 ouputs << "\n" end @fru.each do |key1,value| ouputs <<"#{key1}\t #{key1.calorias*value/100}" @calorias_total = @calorias_total + key1.calorias*value/100 ouputs << "\n" end @cere.each do |key4,value| ouputs <<"#{key4}\t #{key4.calorias*value/100}" @calorias_total = @calorias_total + key4.calorias*value/100 ouputs << "\n" end @protes.each do |key2,value| ouputs <<"#{key2}\t #{key2.calorias*value/100}" @calorias_total = @calorias_total + key2.calorias*value/100 ouputs << "\n" end @grasa.each do |key3,value| ouputs <<"#{key3}\t #{key3.calorias*value/100}" @calorias_total = @calorias_total + key3.calorias*value/100 ouputs << "\n" end ouputs << "Valor energético total \t\t\t #{@calorias_total}" return ouputs end |
#vegetal(alimento, cantidad) ⇒ Object
121 122 123 124 125 |
# File 'lib/pract6/Alimento.rb', line 121 def vegetal(alimento, cantidad) @vege[alimento] = @cambio[cantidad] end |