Class: Plato

Inherits:
Object
  • Object
show all
Defined in:
lib/Alimento/Plato.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block_ingredientes) ⇒ Plato

Returns a new instance of Plato.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/Alimento/Plato.rb', line 6

def initialize(name, &block_ingredientes)
    @name = name
    @ingredients = []

    if block_given?
        if block_ingredientes.arity == 1
            yield self
        else
            instance_eval(&block_ingredientes)
        end
    end

    @tablaAlimentos = [@huevo_frito = Comida.new("Huevo", 14.1, 0.0, 19.5),
        @leche_vaca = Comida.new("Leche vaca", 3.3, 4.8, 3.2),
        @Yogurt = Comida.new("Yogurt", 3.8, 4.9, 3.8),
        @cerdo = Comida.new("Cerdo", 21.5, 0.0, 6.3),
        @ternera = Comida.new("Ternera", 21.1, 0.0, 3.1),
        @pollo = Comida.new("Pollo", 20.6, 0.0, 5.6),
        @bacalao = Comida.new("Bacalao", 17.7, 0.0, 0.4),
        @atun = Comida.new("Atun", 21.5, 0.0, 15.5),
        @salmon = Comida.new("Salmon", 19.9, 0.0, 13.6),
        @aceite_oliva = Comida.new("Aceite de oliva", 0.0, 0.2, 99.6),
        @chocolate = Comida.new("Chocolate", 5.3, 47.0, 30.0),
        @azucar = Comida.new("Azucar", 0.0, 99.8, 0.0),
        @arroz = Comida.new("Arroz", 6.8, 77.7, 0.6),
        @lentejas = Comida.new("Lentejas", 23.5, 52.0, 1.4),
        @papas = Comida.new("Papas", 2.0, 15.4, 0.1),
        @tomate = Comida.new("Tomate", 1.0, 3.5, 0.2),
        @cebolla = Comida.new("Cebolla", 1.3, 5.8, 0.3),
        @platanos = Comida.new("Platano", 1.2, 21.4, 0.2),
        @manzana = Comida.new("Manzana", 0.3, 12.4, 0.4)]

    @tablaValores = [["2 piezas pequeñas", 20], ["1 taza", 10], ["1/2 cucharon", 7], ["1/2 cucharada", 5], ["1 pieza", 15]]
end

Instance Attribute Details

#ingredientsObject

Returns the value of attribute ingredients.



4
5
6
# File 'lib/Alimento/Plato.rb', line 4

def ingredients
  @ingredients
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/Alimento/Plato.rb', line 4

def name
  @name
end

Instance Method Details

#aceite(name, options = {}) ⇒ Object



104
105
106
107
108
109
# File 'lib/Alimento/Plato.rb', line 104

def aceite(name, options = {})
    ingredient = name
    ingredient << "(#{options[:porcion]})" if options[:porcion]

    @ingredients << ingredient
end

#cereal(name, options = {}) ⇒ Object



90
91
92
93
94
95
# File 'lib/Alimento/Plato.rb', line 90

def cereal(name, options = {})
    ingredient = name
    ingredient << "(#{options[:porcion]})" if options[:porcion]

    @ingredients << ingredient
end

#fruta(name, options = {}) ⇒ Object



83
84
85
86
87
88
# File 'lib/Alimento/Plato.rb', line 83

def fruta(name, options = {})
    ingredient = name
    ingredient << "(#{options[:gramos]})" if options[:gramos]

    @ingredients << ingredient
end

#proteina(name, options = {}) ⇒ Object



97
98
99
100
101
102
# File 'lib/Alimento/Plato.rb', line 97

def proteina(name, options = {})
    ingredient = name
    ingredient << "(#{options[:porcion]})" if options[:porcion]

    @ingredients << ingredient
end

#to_sObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/Alimento/Plato.rb', line 41

def to_s
    output = @name
    output << "\n#{'=' * @name.size}\n\n"

    output << "Composicion nutricional:\n"
    output << "#{' ' * 20}glucidos proteinas lipidos valor energetico\n"

    total = 0
    @ingredients.each do |n|
        buscador = "#{n.match(/[^.\(]*/)}"
        output << buscador
        cantidad = "#{n[/\(.*\)/]}"
        cantidad[0] = '' #Elimina el parentisis (
        cantidad[cantidad.length-1] = '' #Elimina el parentisis de la cantidad )

        valor = 0
        @tablaValores.collect do |n|
            n.each_with_index do |m, i|
                if (cantidad == m.to_s)
                    valor = n[1]
                end
            end
        end

        @tablaAlimentos.collect do |n|
            if (n.comida == buscador)
                total += (n.valorEnergetico * valor)
                output << "#{' ' * (20-buscador.size)}#{n.glucidos}         #{n.proteina}      #{n.lipidos}       #{n.valorEnergetico*valor}\n"
            end
        end
    end
    output << "Valor energetico total:                              #{total}"
    output
end

#vegetal(name, options = {}) ⇒ Object



76
77
78
79
80
81
# File 'lib/Alimento/Plato.rb', line 76

def vegetal(name, options = {})
    ingredient = name
    ingredient << "(#{options[:porcion]})" if options[:porcion]

    @ingredients << ingredient
end