Class: Plato

Inherits:
Object
  • Object
show all
Defined in:
lib/pr06/plato.rb

Overview

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, &bloque) ⇒ Plato

Constructor de Plato

Parameters:

  • Nombre (String)

    nombre del Plato

  • bloque (Block)

    Codigo que dicta los ingredientes del plato

Since:

  • 1.0.0



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pr06/plato.rb', line 17

def initialize(nombre, &bloque)

    @nombre = nombre
   @@tabla = [  Alimento.new('Huevo Frito',14.1,0.0,19.5,'lacteos'),
Alimento.new('Leche',3.3,4.8,3.2,'lacteos'),
Alimento.new('Cerdo',21.5,0.0,6.3,'carnes'),
    Alimento.new('Yogurt', 3.8, 4.9, 3.8,'lacteos'),
    Alimento.new("Ternera", 21.1, 0.0, 3.1,'carnes'),
    Alimento.new("Pollo", 20.6, 0.0, 5.6,'carnes'),
    Alimento.new("Bacalao", 17.7, 0.0, 0.4,'pescado'),
    Alimento.new("Atun", 21.5, 0.0, 15.5,'pescado'),
    Alimento.new("Salmon", 19.9, 0.0, 13.6,'pescado'),
    Alimento.new("Aceite de oliva", 0.0, 0.2, 99.6,'al_graso'),
    Alimento.new("Mantequilla", 0.7, 0.0, 83.2,'al_graso'),
    Alimento.new("Chocolate", 5.3, 47.0, 30.0,'al_graso'),
    Alimento.new("Azucar", 0.0, 99.8, 0.0,'al_carbohidratos'),
    Alimento.new("Arroz", 6.8, 77.7, 0.6,'al_carbohidratos'),
    Alimento.new("Lentejas", 23.5, 52.0, 1.4,'al_carbohidratos'),
    Alimento.new("Papas", 2.0, 15.4, 0.1,'al_carbohidratoso'),
    Alimento.new("Tomate", 1.0, 3.5, 0.2,'verduras'),
    Alimento.new("Cebolla", 1.3, 5.8, 0.3,'verduras'),
    Alimentoe.new("Calabaza", 1.1, 4.8, 0.1,'verduras'),
    Alimento.new("Manzana", 0.3, 12.4, 0.4,'fruta'),
    Alimento.new("Platanos", 1.2, 21.4, 0.2,'fruta'),
    Alimento.new("Pera", 0.5 ,12.7, 0.3,'fruta')]
@porciones =[] 
@ingredientes = []
    if block_given?
        if bloque.arity == 1
            yield self
        else
            instance_eval(&bloque)
        end
    end
end

Instance Attribute Details

#ArrayObject (readonly)

ingredientes Conjunto de Alimentos de un plato

Returns:

  • (Object)

    the current value of Array



9
10
11
# File 'lib/pr06/plato.rb', line 9

def Array
  @Array
end

#ingredientesObject (readonly)

Since:

  • 1.0.0



10
11
12
# File 'lib/pr06/plato.rb', line 10

def ingredientes
  @ingredientes
end

#nombreObject (readonly)

Since:

  • 1.0.0



10
11
12
# File 'lib/pr06/plato.rb', line 10

def nombre
  @nombre
end

#porcionesObject (readonly)

Since:

  • 1.0.0



10
11
12
# File 'lib/pr06/plato.rb', line 10

def porciones
  @porciones
end

#StringObject (readonly)

nombre Nombre del plato

Returns:

  • (Object)

    the current value of String



9
10
11
# File 'lib/pr06/plato.rb', line 9

def String
  @String
end

#tablaObject (readonly)

Since:

  • 1.0.0



10
11
12
# File 'lib/pr06/plato.rb', line 10

def tabla
  @tabla
end

Instance Method Details

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

Añade una aceite al plato

Parameters:

  • nombre (String)

    nombre de la fruta

  • options (defaults to: {})

    cantidad de un alimento

Since:

  • 1.0.0



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/pr06/plato.rb', line 142

def aceite(nombre, options = {})
    tabla.each_with_index do |s , i|
        if (s.nombre == nombre)
            @ingredientes << tabla[i]
            break
        end
    end
    if (options[:gramos])
        @porciones << options[:gramos]
    else if (options[:porciones])
        dummyString = options[:porciones]
        @porciones << dummyString.scan(/\d+\.\d+/).first.to_f
    end
    end
end

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

Añade una fruta al plato

Parameters:

  • nombre (String)

    nombre de la fruta

  • options (defaults to: {})

    cantidad de un alimento

Since:

  • 1.0.0



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/pr06/plato.rb', line 70

def fruta(nombre, options = {})
    tabla.each_with_index do |s , i|
        if (s.nombre == nombre)
            @ingredientes << tabla[i]
            break
        end
    end
    if (options[:gramos])
        @porciones << options[:gramos]
    else if (options[:porciones])
        dummyString = options[:porciones]
        @porciones << dummyString.scan(/\d+\.\d+/).first.to_f
    end
    end
end

#granos_integrales(nombre, options = {}) ⇒ Object

Añade un grano al plato al plato

Parameters:

  • nombre (String)

    nombre de la fruta

  • options (defaults to: {})

    cantidad de un alimento

Since:

  • 1.0.0



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/pr06/plato.rb', line 124

def granos_integrales(nombre, options = {})
    tabla.each_with_index do |s , i|
        if (s.nombre == nombre)
            @ingredientes << tabla[i]
            break
        end
    end
    if (options[:gramos])
        @porciones << options[:gramos]
    else if (options[:porciones])
        dummyString = " (#{options[:porciones]})"
        @porciones << dummyString.scan(/\d+\.\d+/).first.to_f
    end
    end
end

#proteinas(nombre, options = {}) ⇒ Object

Añade una proteina al plato

Parameters:

  • nombre (String)

    nombre de la fruta

  • options (defaults to: {})

    cantidad de un alimento

Since:

  • 1.0.0



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pr06/plato.rb', line 106

def proteinas(nombre, options = {})
    tabla.each_with_index do |s , i|
        if (s.nombre == nombre)
            @ingredientes << tabla[i]
            break
        end
    end
    if (options[:gramos])
        @porciones << options[:gramos]
    else if (options[:porciones])
        dummyString = options[:porciones]
        @porciones << dummyString.scan(/\d+\.\d+/).first.to_f
    end
    end
end

#to_sString

Convierte el objeto en un String

Returns:

  • (String)

    descripción del plato en una cadena de caracteres

Since:

  • 1.0.0



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pr06/plato.rb', line 55

def to_s
    texto = @nombre
    texto << "\n#{'=' * @nombre.size}\n"
    texto << "Composicion nutricional: \n"
    @ingredientes.each_with_index do |i , p|
        texto << i.to_s
        texto << "#{i.kcal * @porciones[p]}"
        texto << "\n"
    end
    return texto
end

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

Añade un vegetal al plato

Parameters:

  • nombre (String)

    nombre de la fruta

  • options (defaults to: {})

    cantidad de un alimento

Since:

  • 1.0.0



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/pr06/plato.rb', line 88

def vegetal(nombre, options = {})
    tabla.each_with_index do |s , i|
        if (s.nombre == nombre)
            @ingredientes << tabla[i]
            break
        end
    end
    if (options[:gramos])
        @porciones << options[:gramos]
    else if (options[:porciones])
        dummyString = options[:porciones]
        @porciones << dummyString.scan(/\d+\.\d+/).first.to_f
    end
    end
end