Class: HarvardDish
- Inherits:
-
Object
- Object
- HarvardDish
- Defined in:
- lib/nutrientes/harvard_dish.rb
Constant Summary collapse
- @@list =
[OvoLacteo.new("Huevo frito", 14.1, 0.0, 19.5), OvoLacteo.new("Leche de vaca", 3.3, 4.8, 3.2), OvoLacteo.new("Yogurt", 3.8, 4.9, 3.8), Carnido.new("Cerdo", 21.5, 0.0, 6.3), Carnido.new("Ternera", 21.1, 0.0, 3.1), Carnido.new("Pollo", 20.6, 0.0, 5.6), Pescado.new("Bacalao", 17.7, 0.0, 0.4), Pescado.new("Atún", 21.5, 0.0, 15.5), Pescado.new("Salmón", 19.9, 0.0, 13.6), Graso.new("Aceite de oliva", 0.0, 0.2, 99.6), Graso.new("Mantequilla", 0.7, 0.0, 83.2), Graso.new("Chocolate", 5.3, 47.0, 30.0), Carbohidratado.new("Azúcar", 0.0, 99.8, 0.0), Carbohidratado.new("Arroz", 6.8, 77.7, 0.6), Carbohidratado.new("Lentejas", 23.5, 52.0, 1.4), Carbohidratado.new("Papas", 2.0, 15.4, 0.1), Verdura.new("Tomate", 1.0, 3.5, 0.2), Verdura.new("Cebolla", 1.3, 5.8, 0.3), Verdura.new("Calabaza", 1.1, 4.8, 0.1), Fruta.new("Manzana", 0.3, 12.4, 0.4), Fruta.new("Plátano", 1.2, 21.4, 0.2), Fruta.new("Pera", 0.5 ,12.7, 0.3)]
- @@proportions =
[["/piezas? pequeña/", 2], ["/pieza/" , 4], ["/taza/" , 0.6], ["/cuchara/" , 0.4], ["/cuchar[o|ó]n/" , 0.8], ["/vaso/" , 1.2], ["/gramo/" , 1], ["/pizca/" , 0.5]]
Instance Method Summary collapse
- #ingredient(nombre, cantidad) ⇒ Object
-
#initialize(name, &block) ⇒ HarvardDish
constructor
A new instance of HarvardDish.
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ HarvardDish
Returns a new instance of HarvardDish.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nutrientes/harvard_dish.rb', line 41 def initialize(name, &block) @name = name @ingredients = [] @amounts = [] @cv_total = 0 if block_given? if block.arity == 1 then yield self else instance_eval(&block) end end end |
Instance Method Details
#ingredient(nombre, cantidad) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/nutrientes/harvard_dish.rb', line 68 def ingredient(nombre, cantidad) @@list.each_index do |i| if @@list[i].name == nombre then @ingredients << @@list[i] numero = /\d/.match(cantidad) multiplier = 0 @@proportions.each_index do |j| expr = Regexp.new @@proportions[j][0] if expr.match(cantidad) != nil then multiplier = @@proportions[j][1] break; end end multiplier += numero[0].to_i @amounts << multiplier break end end end |
#to_s ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/nutrientes/harvard_dish.rb', line 56 def to_s() output = @name output << "\n#{'=' * @name.size}\n" output << "Nombre Proteínas Glúcidos Lípidos Valor calórico\n" @ingredients.each_index do |i| output << @ingredients[i].name << " " << @ingredients[i].proteins.to_s << " " << @ingredients[i].glucids.to_s << " " << @ingredients[i].lipids.to_s << " " << (@ingredients[i].caloric_value * @amounts[i]).to_s << "\n" @cv_total += (@ingredients[i].caloric_value * @amounts[i]) end output << "Valor calórico total: " << @cv_total.to_s << "\n" return output end |