Class: Alimento::Plato
- Inherits:
-
Object
- Object
- Alimento::Plato
- Defined in:
- lib/alimento/fuente.rb
Overview
Clase que permite representar una receta
Instance Attribute Summary collapse
-
#aceites ⇒ Object
readonly
Returns the value of attribute aceites.
-
#frutas ⇒ Object
readonly
Returns the value of attribute frutas.
-
#granos ⇒ Object
readonly
Returns the value of attribute granos.
-
#proteinas ⇒ Object
readonly
Returns the value of attribute proteinas.
-
#vegetales ⇒ Object
readonly
Returns the value of attribute vegetales.
Instance Method Summary collapse
-
#aceite(name, options = {}) ⇒ Object
Metodo que inserta aceite al plato.
-
#cereal(name, options = {}) ⇒ Object
Metodo que inserta un cereal al plato.
-
#fruta(name, options = {}) ⇒ Object
Metodo que inserta una fruta al plato.
-
#initialize(name, &block) ⇒ Plato
constructor
Se definen los valores de conversion en @tabla y la lista de alimentos disponibles en @listaalimentos junto con el nombre de la receta en @name.
-
#proteina(name, options = {}) ⇒ Object
Metodo que inserta proteinas al plato.
-
#to_s ⇒ Object
Metodo que transforma el objeto plato en una tabla representada en un string.
-
#vegetal(name, options = {}) ⇒ Object
Metodo que inserta un vegetal al plato.
Constructor Details
#initialize(name, &block) ⇒ Plato
Se definen los valores de conversion en @tabla y la lista de alimentos disponibles en @listaalimentos junto con el nombre de la receta en @name
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 182 183 184 185 186 187 188 |
# File 'lib/alimento/fuente.rb', line 154 def initialize(name,&block) @name=name @vegetales=[] @frutas=[] @granos=[] @proteinas=[] @aceites=[] @tabla={"cups" => 2, "piece" => 1, "glass" => 1.5, "grams" => 0.05 } @listaalimentos=[ DerivadoLacteo.new("Huevo", 14.1,0,19.5), DerivadoLacteo.new("Leche", 3.3,4.8,3.2), DerivadoLacteo.new("Yogurt", 3.8,4.9,3.8), Carnes.new("Cerdo", 21.5,0,6.3), Carnes.new("ternera", 21.1,0,3.1), Carnes.new("pollo", 20.6,0,5.6), Pescados.new("bacalao", 17.7,0,0.4), Pescados.new("atun", 21.5,0,15.5), Pescados.new("salmon", 19.9,0,13.6), Grasos.new("aceite de oliva", 0,0.2,99.6), Grasos.new("mantequilla", 0.7,0,83.2), Grasos.new("chocolate", 5.3,47.0,30.0), Carbohidratos.new("azucar", 0,99.8,0), Carbohidratos.new("arroz", 6.8,77.7,0.6), Carbohidratos.new("lentejas", 23.5,52.0,1.4), Carbohidratos.new("papas", 2,15.4,0.1), Verduras.new("tomate", 1,3.5,0.2), Verduras.new("cebolla", 1.3,5.8,0.3), Verduras.new("calabaza", 1.1,4.8,0.1), Frutas.new("manzana", 0.3,12.4,0.4), Frutas.new("platano", 1.2,21.4,0.2), Frutas.new("pera", 0.5,12.7,0.3)] if block_given? instance_eval(&block) end end |
Instance Attribute Details
#aceites ⇒ Object (readonly)
Returns the value of attribute aceites
151 152 153 |
# File 'lib/alimento/fuente.rb', line 151 def aceites @aceites end |
#frutas ⇒ Object (readonly)
Returns the value of attribute frutas
151 152 153 |
# File 'lib/alimento/fuente.rb', line 151 def frutas @frutas end |
#granos ⇒ Object (readonly)
Returns the value of attribute granos
151 152 153 |
# File 'lib/alimento/fuente.rb', line 151 def granos @granos end |
#proteinas ⇒ Object (readonly)
Returns the value of attribute proteinas
151 152 153 |
# File 'lib/alimento/fuente.rb', line 151 def proteinas @proteinas end |
#vegetales ⇒ Object (readonly)
Returns the value of attribute vegetales
151 152 153 |
# File 'lib/alimento/fuente.rb', line 151 def vegetales @vegetales end |
Instance Method Details
#aceite(name, options = {}) ⇒ Object
Metodo que inserta aceite al plato
251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/alimento/fuente.rb', line 251 def aceite(name, = {}) aceite=@listaalimentos.select do |alimento| alimento.nombre.downcase == name.downcase end if [:porcion] info=[:porcion].split(/\W+/) amount=info[0].to_i*@tabla[info[1]] aceite << amount; end @aceites << aceite end |
#cereal(name, options = {}) ⇒ Object
Metodo que inserta un cereal al plato
221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/alimento/fuente.rb', line 221 def cereal(name, = {}) cereal=@listaalimentos.select do |alimento| alimento.nombre.downcase == name.downcase end if [:porcion] info=[:porcion].split(/\W+/) amount=info[0].to_i*@tabla[info[1]] cereal << amount; end @granos << cereal end |
#fruta(name, options = {}) ⇒ Object
Metodo que inserta una fruta al plato
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/alimento/fuente.rb', line 206 def fruta(name, = {}) fruta=@listaalimentos.select do |alimento| alimento.nombre.downcase == name.downcase end if [:porcion] info=[:porcion].split(/\W+/) amount=info[0].to_i*@tabla[info[1]] fruta << amount; end @frutas << fruta end |
#proteina(name, options = {}) ⇒ Object
Metodo que inserta proteinas al plato
236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/alimento/fuente.rb', line 236 def proteina(name, = {}) proteinas=@listaalimentos.select do |alimento| alimento.nombre.downcase == name.downcase end if [:porcion] info=[:porcion].split(/\W+/) amount=info[0].to_i*@tabla[info[1]] proteinas << amount; end @proteinas << proteinas end |
#to_s ⇒ Object
Metodo que transforma el objeto plato en una tabla representada en un string
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/alimento/fuente.rb', line 266 def to_s output = @name output << "\n#{'='*@name.size}\n\n" output << "Composicion Nutricional:\n\n" output << "%-20s %12s %12s %12s %20s\n" % ["NOMBRE","GLUCIDOS","PROTEINAS","LIPIDOS","VALOR ENERGETICO"] @vegetales.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] } @granos.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] } @frutas.each{ |i| output <<"%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] } @proteinas.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] } @aceites.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] } total=0 @vegetales.each{ |i| total += i[0].energeticValue*i[1] } @granos.each{ |i| total += i[0].energeticValue*i[1] } @frutas.each{ |i| total += i[0].energeticValue*i[1] } @proteinas.each{ |i| total += i[0].energeticValue*i[1] } @aceites.each{ |i| total += i[0].energeticValue*i[1] } output << "\nTOTAL: %73.2f" % [total] end |
#vegetal(name, options = {}) ⇒ Object
Metodo que inserta un vegetal al plato
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/alimento/fuente.rb', line 191 def vegetal(name, = {}) vegetal=@listaalimentos.select do |alimento| alimento.nombre.downcase == name.downcase end if [:porcion] info=[:porcion].split(/\W+/) amount=info[0].to_i*@tabla[info[1]] vegetal << amount; end @vegetales<<vegetal end |