Class: PlatoHardvard
- Inherits:
-
Object
- Object
- PlatoHardvard
- Defined in:
- lib/alimento/platohardvard.rb
Instance Attribute Summary collapse
-
#entotal ⇒ Object
Returns the value of attribute entotal.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platos ⇒ Object
Returns the value of attribute platos.
Instance Method Summary collapse
- #aceite(titulo, options = {}) ⇒ Object
- #cereal(titulo, options = {}) ⇒ Object
- #fruta(titulo, options = {}) ⇒ Object
-
#initialize(name, &block) ⇒ PlatoHardvard
constructor
A new instance of PlatoHardvard.
- #proteina(titulo, options = {}) ⇒ Object
- #to_s ⇒ Object
-
#vegetal(titulo, options = {}) ⇒ Object
funciones del block.
Constructor Details
#initialize(name, &block) ⇒ PlatoHardvard
Returns a new instance of PlatoHardvard.
4 5 6 7 8 9 10 |
# File 'lib/alimento/platohardvard.rb', line 4 def initialize(name, &block) self.name = name self.platos = [] self.entotal = 0 instance_eval &block end |
Instance Attribute Details
#entotal ⇒ Object
Returns the value of attribute entotal.
2 3 4 |
# File 'lib/alimento/platohardvard.rb', line 2 def entotal @entotal end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/alimento/platohardvard.rb', line 2 def name @name end |
#platos ⇒ Object
Returns the value of attribute platos.
2 3 4 |
# File 'lib/alimento/platohardvard.rb', line 2 def platos @platos end |
Instance Method Details
#aceite(titulo, options = {}) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/alimento/platohardvard.rb', line 114 def aceite(titulo, = {}) porcion = "" porcion << " (#{[:porcion]})" if [:porcion] porcion = porcion.tr("^0-9","") gramos = "" gramos << " (#{[:gramos]})" if [:gramos] gramos = gramos.tr("^0-9","") if gramos != "" glucidos = (gramos.to_f * 10 * 30)/100 lipidos = (gramos.to_f * 10 * 20)/100 proteinas = (gramos.to_f * 10 * 50)/100 end if porcion != "" glucidos = (porcion.to_f * 5 * 30)/100 lipidos = (porcion.to_f * 5 * 20)/100 proteinas = (porcion.to_f * 5 * 50)/100 end alimento = Alimentos.new(titulo,glucidos,proteinas,lipidos) @entotal = @entotal + alimento.get_energetico() platos << alimento end |
#cereal(titulo, options = {}) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/alimento/platohardvard.rb', line 64 def cereal(titulo, = {}) porcion = "" porcion << " (#{[:porcion]})" if [:porcion] porcion = porcion.tr("^0-9","") gramos = "" gramos << " (#{[:gramos]})" if [:gramos] gramos = gramos.tr("^0-9","") if gramos != "" glucidos = (gramos.to_f * 10 * 30)/100 lipidos = (gramos.to_f * 10 * 20)/100 proteinas = (gramos.to_f * 10 * 50)/100 end if porcion != "" glucidos = (porcion.to_f * 10 * 30)/100 lipidos = (porcion.to_f * 10 * 20)/100 proteinas = (porcion.to_f * 10 * 50)/100 end alimento = Alimentos.new(titulo,glucidos,proteinas,lipidos) @entotal = @entotal + alimento.get_energetico() platos << alimento end |
#fruta(titulo, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/alimento/platohardvard.rb', line 39 def fruta(titulo, = {}) porcion = "" porcion << " (#{[:porcion]})" if [:porcion] porcion = porcion.tr("^0-9","") gramos = "" gramos << " (#{[:gramos]})" if [:gramos] gramos = gramos.tr("^0-9","") if gramos != "" glucidos = (gramos.to_f * 3 * 30)/100 lipidos = (gramos.to_f * 3 * 20)/100 proteinas = (gramos.to_f * 3 * 50)/100 end if porcion != "" glucidos = (porcion.to_f * 10 * 30)/100 lipidos = (porcion.to_f * 10 * 20)/100 proteinas = (porcion.to_f * 10 * 50)/100 end alimento = Alimentos.new(titulo,glucidos,proteinas,lipidos) @entotal = @entotal + alimento.get_energetico() platos << alimento end |
#proteina(titulo, options = {}) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/alimento/platohardvard.rb', line 89 def proteina(titulo, = {}) porcion = "" porcion << " (#{[:porcion]})" if [:porcion] porcion = porcion.tr("^0-9","") gramos = "" gramos << " (#{[:gramos]})" if [:gramos] gramos = gramos.tr("^0-9","") if gramos != "" glucidos = (gramos.to_f * 10 * 30)/100 lipidos = (gramos.to_f * 10 * 20)/100 proteinas = (gramos.to_f * 10 * 50)/100 end if porcion != "" glucidos = (porcion.to_f * 10 * 30)/100 lipidos = (porcion.to_f * 10 * 20)/100 proteinas = (porcion.to_f * 10 * 50)/100 end alimento = Alimentos.new(titulo,glucidos,proteinas,lipidos) @entotal = @entotal + alimento.get_energetico() platos << alimento end |
#to_s ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/alimento/platohardvard.rb', line 139 def to_s output = "" output << name output << "\n" for i in 0..name.size-1 do output << "=" end output << "\n" output << "\nComposiciĆ³n nutricional:\n" output << "\n" platos.each_with_index do |plato, index| output << "#{plato} #{plato.get_energetico}\n" #if index>0 #if (index-1) % 3 == 1 #output << "\n" #end #end end output << "Valor Energetico total #{@entotal}" output end |
#vegetal(titulo, options = {}) ⇒ Object
funciones del block
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/alimento/platohardvard.rb', line 14 def vegetal(titulo, = {}) porcion = "" porcion << " (#{[:porcion]})" if [:porcion] porcion = porcion.tr("^0-9","") gramos = "" gramos << " (#{[:gramos]})" if [:gramos] gramos = gramos.tr("^0-9","") if gramos != "" glucidos = (gramos.to_f * 10 * 30)/100 lipidos = (gramos.to_f * 10 * 20)/100 proteinas = (gramos.to_f * 10 * 50)/100 end if porcion != "" glucidos = (porcion.to_f * 10 * 30)/100 lipidos = (porcion.to_f * 10 * 20)/100 proteinas = (porcion.to_f * 10 * 50)/100 end alimento = Alimentos.new(titulo,glucidos,proteinas,lipidos) @entotal = @entotal + alimento.get_energetico() platos << alimento end |