Class: Plato
- Inherits:
-
Object
- Object
- Plato
- Defined in:
- lib/plato.rb
Overview
this class represents plates that follow the concept of harvard health experts
Constant Summary collapse
- @@tabla =
all known foods that can be inside a plate
[ HuevosLacteosHelados.new("Huevo", 14.1, 0.0, 19.5), HuevosLacteosHelados.new("Leche", 3.3, 4.8, 3.2), HuevosLacteosHelados.new("Yogurt", 3.8, 4.9, 3.8), CarnesDerivados.new("Cerdo", 21.5, 0.0, 6.3), CarnesDerivados.new("Ternera", 21.1, 0.0, 3.1), CarnesDerivados.new("Pollo", 20.6, 0.0, 5.6), PescadosMariscos.new("Bacalao", 17.7, 0.0, 0.4), PescadosMariscos.new("Atún", 21.5, 0.0, 15.5), PescadosMariscos.new("Salmón", 19.9, 0.0, 13.6), AlimentosGrasos.new("Aceite de oliva", 0.0, 0.2, 99.6), AlimentosGrasos.new("Mantequilla", 0.7, 0.0, 83.2), AlimentosGrasos.new("Chocolate", 5.3, 47.0, 30.0), AlimentosCarbohidratos.new("Azúcar", 0.0, 99.8, 0.0), AlimentosCarbohidratos.new("Arroz", 6.8, 77.7, 0.6), AlimentosCarbohidratos.new("Lentejas", 23.5, 52.0, 1.4), AlimentosCarbohidratos.new("Papas", 2.0, 15.4, 0.1), VerdurasHortalizas.new("Tomate", 1.0, 3.5, 0.2), VerdurasHortalizas.new("Cebolla", 1.3, 5.8, 0.3), VerdurasHortalizas.new("Calabaza", 1.1, 4.8, 0.1), Frutas.new("Manzana", 0.3, 12.4, 0.4), Frutas.new("Plátano", 1.2, 21.4, 0.2), Frutas.new("Pera", 0.5, 12.7, 0.3) ]
- @@unityConverter =
{ "piezas pequeñas" => 30, "pieza pequeña" => 30, "taza" => 200, "tazas" => 200, "cucharón" => 70, "cucharónes" => 70, "pieza" => 50, "piezas" => 50, "cucharada" => 10, "cucharadas" => 10 }
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #aceite(name, amount) ⇒ Object
- #adjust(str, length) ⇒ Object
- #cereal(name, amount) ⇒ Object
- #format(alimento) ⇒ Object
- #fruta(name, amount) ⇒ Object
-
#initialize(name, &bloque) ⇒ Plato
constructor
A new instance of Plato.
- #proteina(name, amount) ⇒ Object
- #to_s ⇒ Object
- #translateAmount(amount) ⇒ Object
- #vegetal(name, amount) ⇒ Object
Constructor Details
#initialize(name, &bloque) ⇒ Plato
Returns a new instance of Plato.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/plato.rb', line 48 def initialize(name, &bloque) @name = name.strip @ingredients = { "vegetales" => [], "frutas" => [], "granos" => [], "proteina" => [], "aceite" => [] } @valorEnergetico = 0 if block_given? if bloque.arity == 1 yield self else instance_eval(&bloque) end end end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/plato.rb', line 9 def name @name end |
Instance Method Details
#aceite(name, amount) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/plato.rb', line 96 def aceite(name, amount) @@tabla.each{ |value| if value.nombre == name @ingredients["aceite"] << [value, translateAmount(amount)] @valorEnergetico += value.valorEnergetico(translateAmount(amount)) end } end |
#adjust(str, length) ⇒ Object
137 138 139 140 |
# File 'lib/plato.rb', line 137 def adjust(str, length) str = str.to_s str + " " * (length - str.length) end |
#cereal(name, amount) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/plato.rb', line 82 def cereal(name, amount) @@tabla.each{ |value| if value.nombre == name @ingredients["granos"] << [value, translateAmount(amount)] @valorEnergetico += value.valorEnergetico(translateAmount(amount)) end } end |
#format(alimento) ⇒ Object
132 133 134 135 |
# File 'lib/plato.rb', line 132 def format(alimento) value = alimento[0] str = adjust(value.nombre, 17) + "#{adjust(value.glucidos, 12)}#{adjust(value.proteinas, 12)}#{adjust(value.grasas, 12)}#{adjust(value.valorEnergetico(alimento[1]).round(1), 6)}(#{alimento[1].round} gramos)\n" end |
#fruta(name, amount) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/plato.rb', line 75 def fruta(name, amount) @@tabla.each{ |value| if value.nombre == name @ingredients["frutas"] << [value, translateAmount(amount)] @valorEnergetico += value.valorEnergetico(translateAmount(amount)) end } end |
#proteina(name, amount) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/plato.rb', line 89 def proteina(name, amount) @@tabla.each{ |value| if value.nombre == name @ingredients["proteina"] << [value, translateAmount(amount)] @valorEnergetico += value.valorEnergetico(translateAmount(amount)) end } end |
#to_s ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/plato.rb', line 117 def to_s text = @name text << "\n" temp = "=" * (@name.length-1) text << temp text << "\nComposición nutricional\n" text << " glúcidos proteínas lípidos valor energético\n" #17 spaces @ingredients.each{|temp| temp[1].each {|alimento| text << format(alimento)}} text << adjust("Valor energético total", 53) text << @valorEnergetico.round(1).to_s text end |
#translateAmount(amount) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/plato.rb', line 104 def translateAmount(amount) if amount[:gramos] != nil amount[:gramos] elsif amount[:porcion] != nil text = amount[:porcion].partition(" ") number = text[0].strip.to_f amount = @@unityConverter[text[2].strip.to_s] number * amount else nil end end |
#vegetal(name, amount) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/plato.rb', line 68 def vegetal(name, amount) @@tabla.each{ |value| if value.nombre == name @ingredients["vegetales"] << [value, translateAmount(amount)] @valorEnergetico += value.valorEnergetico(translateAmount(amount)) end } end |