Class: Plato::Plato
- Inherits:
-
Object
- Object
- Plato::Plato
- Defined in:
- lib/nutrientes/source.rb
Overview
Clase Plato que contine la información del alimento al igual que sus ingredientes
Instance Attribute Summary collapse
-
#ingredientes ⇒ Object
Atributos de la Clase Plato accesibles desde el exterior de la clase.
-
#name ⇒ Object
Atributos de la Clase Plato accesibles desde el exterior de la clase.
Instance Method Summary collapse
- #aceite(name, options = {}) ⇒ Object
- #cereal(name, options = {}) ⇒ Object
- #fruta(name, options = {}) ⇒ Object
-
#initialize(name, &block) ⇒ Plato
constructor
Método initialize para definir un objeto Plato con los atributos (Bloque).
- #proteina(name, options = {}) ⇒ Object
- #to_s ⇒ Object
- #vegetal(name, options = {}) ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Plato
Método initialize para definir un objeto Plato con los atributos (Bloque)
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/nutrientes/source.rb', line 271 def initialize(name, &block) @name = name @vec_vegetales = [] @vec_fruta = [] @vec_cereal = [] @vec_proteina = [] @vec_aceite = [] @vec_ingredientes = [] @lista_alimentos = { "huevo" => Nutrientes::Nutrientes.new("Huevofri",14.1,0.0,19.5,0), "leche" => Nutrientes::Nutrientes.new("Leche vaca",3.3,4.8,3.2,0), "yogurt" => Nutrientes::Nutrientes.new("Yogurt",3.8,4.9,3.8,0), "cerdo" => Nutrientes::Nutrientes.new("Cerdo",21.5,0.0,6.3,0), "ternera" => Nutrientes::Nutrientes.new("Ternera",21.1,0.0,3.1,0), "pollo" => Nutrientes::Nutrientes.new("Pollo",20.6,0.0,5.6,0), "bacalao" => Nutrientes::Nutrientes.new("Bacalao",17.7,0.0,0.4,0), "atun" => Nutrientes::Nutrientes.new("Atún",21.5,0.0,15.5,0), "salmon" => Nutrientes::Nutrientes.new("Salmón",19.9,0.0,13.6,0), "aceite" => Nutrientes::Nutrientes.new("Aceite Oliva",0.0,0.2,99.6,0), "chocolate" => Nutrientes::Nutrientes.new("Chocolate",5.3,47.0,30.0,0), "azucar" => Nutrientes::Nutrientes.new("Azúcar",0.0,99.8,0.0,0), "arroz" => Nutrientes::Nutrientes.new("Arroz",6.8,77.7,0.6,0), "lentejas" => Nutrientes::Nutrientes.new("Lentejas",23.5,52.0,1.4,0), "papas" => Nutrientes::Nutrientes.new("Papas",2.0,15.4,0.1,0), "tomate" => Nutrientes::Nutrientes.new("Tomate",1.0,3.5,0.2,0), "cebolla" => Nutrientes::Nutrientes.new("Cebolla",1.3,5.8,0.3,0), "manzana" => Nutrientes::Nutrientes.new("Manzana",0.3,12.4,0.4,0), "platano" => Nutrientes::Nutrientes.new("Plátanos",1.2,21.4,0.2,0), "calabaza" => Nutrientes::Nutrientes.new("Calabaza",1.1,4.8,0.1,0) } if block_given? if block.arity == 1 yield self else instance_eval(&block) end end end |
Instance Attribute Details
#ingredientes ⇒ Object
Atributos de la Clase Plato accesibles desde el exterior de la clase.
268 269 270 |
# File 'lib/nutrientes/source.rb', line 268 def ingredientes @ingredientes end |
#name ⇒ Object
Atributos de la Clase Plato accesibles desde el exterior de la clase.
268 269 270 |
# File 'lib/nutrientes/source.rb', line 268 def name @name end |
Instance Method Details
#aceite(name, options = {}) ⇒ Object
349 350 351 352 353 354 355 356 |
# File 'lib/nutrientes/source.rb', line 349 def aceite(name, = {}) ingredient = @lista_alimentos[name.downcase] amount = [:porcion] amount = amount.split(/\W+/) amount[0] = amount[0].to_i aux = [ingredient,amount] @vec_aceite << aux end |
#cereal(name, options = {}) ⇒ Object
331 332 333 334 335 336 337 338 |
# File 'lib/nutrientes/source.rb', line 331 def cereal(name, = {}) ingredient = @lista_alimentos[name.downcase] amount = [:porcion] amount = amount.split(/\W+/) amount[0] = amount[0].to_i aux = [ingredient,amount] @vec_cereal << aux end |
#fruta(name, options = {}) ⇒ Object
322 323 324 325 326 327 328 329 |
# File 'lib/nutrientes/source.rb', line 322 def fruta(name, = {}) ingredient = @lista_alimentos[name.downcase] amount = [:porcion] amount = amount.split(/\W+/) amount[0] = amount[0].to_i aux = [ingredient,amount] @vec_fruta << aux end |
#proteina(name, options = {}) ⇒ Object
340 341 342 343 344 345 346 347 |
# File 'lib/nutrientes/source.rb', line 340 def proteina(name, = {}) ingredient = @lista_alimentos[name.downcase] amount = [:porcion] amount = amount.split(/\W+/) amount[0] = amount[0].to_i aux = [ingredient,amount] @vec_proteina << aux end |
#to_s ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
# File 'lib/nutrientes/source.rb', line 358 def to_s medidas = { "gramos" => 0.02, "tazas" => 1, "piezas" => 2, "cucharon" => 1, "cucharada" => 1} sum = 0 output = @name output << "\n#{'=' * @name.size}\n\n" output << "Composición nutricional: \n" output << " Glúcidos Proteínas Lípidos Valor Energético\n" @vec_vegetales.each do |i| output << i[0].nombre << " " << i[0].glucidos.to_s << " " << i[0].proteina.to_s << " " << i[0].lipidos.to_s << " " << (i[0].valorEnergetico*medidas[i[1][1]]*i[1][0]).to_s << "\n" sum += i[0].valorEnergetico*medidas[i[1][1]]*i[1][0] end @vec_fruta.each do |i| output << i[0].nombre << " " << i[0].glucidos.to_s << " " << i[0].proteina.to_s << " " << i[0].lipidos.to_s << " " << (i[0].valorEnergetico*medidas[i[1][1]]*i[1][0]).to_s << "\n" sum += i[0].valorEnergetico**medidas[i[1][1]]*i[1][0] end @vec_cereal.each do |i| output << i[0].nombre << " " << i[0].glucidos.to_s << " " << i[0].proteina.to_s << " " << i[0].lipidos.to_s << " " << (i[0].valorEnergetico*medidas[i[1][1]]*i[1][0]).to_s << "\n" sum += i[0].valorEnergetico*medidas[i[1][1]]*i[1][0] end @vec_proteina.each do |i| output << i[0].nombre << " " << i[0].glucidos.to_s << " " << i[0].proteina.to_s << " " << i[0].lipidos.to_s << " " << (i[0].valorEnergetico*medidas[i[1][1]]*i[1][0]).to_s << "\n" sum += i[0].valorEnergetico*medidas[i[1][1]]*i[1][0] end @vec_aceite.each do |i| output << i[0].nombre << " " << i[0].glucidos.to_s << " " << i[0].proteina.to_s << " " << i[0].lipidos.to_s << " " << (i[0].valorEnergetico*medidas[i[1][1]]*i[1][0]).to_s << "\n" sum += i[0].valorEnergetico*medidas[i[1][1]]*i[1][0] end output << "Valor energético total " << sum.to_s output end |
#vegetal(name, options = {}) ⇒ Object
313 314 315 316 317 318 319 320 |
# File 'lib/nutrientes/source.rb', line 313 def vegetal(name, = {}) ingredient = @lista_alimentos[name.downcase] amount = [:porcion] amount = amount.split(/\W+/) amount[0] = amount[0].to_i aux = [ingredient,amount] @vec_vegetales << aux end |