Class: Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/Ein/menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dia, &block) ⇒ Menu

Returns a new instance of Menu.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/Ein/menu.rb', line 6

def initialize (dia, &block)

    @dia = dia
    @titulo = nil
    @ingestas = []
    @desayunos = []
    @almuerzos = []
    @cenas = []
    
    if block_given?
        if block.arity == 1
            yield self
        else
            instance_eval(&block)
        end
    end

end

Instance Attribute Details

#almuerzosObject

Returns the value of attribute almuerzos.



3
4
5
# File 'lib/Ein/menu.rb', line 3

def almuerzos
  @almuerzos
end

#cenasObject

Returns the value of attribute cenas.



3
4
5
# File 'lib/Ein/menu.rb', line 3

def cenas
  @cenas
end

#desayunosObject

Returns the value of attribute desayunos.



3
4
5
# File 'lib/Ein/menu.rb', line 3

def desayunos
  @desayunos
end

#diaObject

Returns the value of attribute dia.



3
4
5
# File 'lib/Ein/menu.rb', line 3

def dia
  @dia
end

#ingestasObject

Returns the value of attribute ingestas.



3
4
5
# File 'lib/Ein/menu.rb', line 3

def ingestas
  @ingestas
end

#titulo(tit) ⇒ Object

Returns the value of attribute titulo.



3
4
5
# File 'lib/Ein/menu.rb', line 3

def titulo
  @titulo
end

Instance Method Details

#almuerzo(alm, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/Ein/menu.rb', line 60

def almuerzo (alm, options = {})

    almuerzo = alm
    
    almuerzo << "(#{options[:descripcion]})" if options[:descripcion] 
    almuerzo << "(#{options[:porcion]})" if options[:porcion] 
    almuerzo << "(#{options[:gramos]})" if options[:gramos] 
    almuerzo << "(#{options[:grasas]})" if options[:grasas]  
    almuerzo << "(#{options[:carbohidratos]})" if options[:carbohidratos] 
    almuerzo << "(#{options[:proteinas]})" if options[:proteinas] 
    almuerzo << "(#{options[:fibra]})" if options[:fibra] 
    almuerzo << "(#{options[:sal]})" if options[:sal] 
    
    @almuerzos << almuerzo

end

#cena(cen, options = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/Ein/menu.rb', line 78

def cena (cen, options = {})

    cena = cen
    
    cena << "(#{options[:descripcion]})" if options[:descripcion]
    cena << "(#{options[:porcion]})" if options[:porcion]
    cena << "(#{options[:gramos]})" if options[:gramos]
    cena << "(#{options[:grasas]})" if options[:grasas]
    cena << "(#{options[:carbohidratos]})" if options[:carbohidratos]
    cena << "(#{options[:proteinas]})" if options[:proteinas]
    cena << "(#{options[:fibra]})" if options[:fibra]
    cena << "(#{options[:sal]})" if options[:sal]
    
    @cenas << cena


end

#desayuno(des, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/Ein/menu.rb', line 43

def desayuno (des, options = {})

    desayuno = des
    desyuno << "(#{options[:descripcion]})" if options[:descripcion]
    desyuno << "(#{options[:porcion]})" if options[:porcion]
    desyuno << "(#{options[:gramos]})" if options[:gramos]
    desyuno << "(#{options[:grasas]})" if options[:grasas]
    desyuno << "(#{options[:carbohidratos]})" if options[:carbohidratos]
    desyuno << "(#{options[:proteinas]})" if options[:proteinas]
    desyuno << "(#{options[:fibra]})" if options[:fibra]
    desyuno << "(#{options[:sal]})" if options[:sal]
    
    @desayunos << desayuno

end

#ingesta(ing, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/Ein/menu.rb', line 32

def ingesta(ing, options = {})

    ingesta = ing
    ingesta << "(#{options[:min]})" if options[:min]
    ingesta << "(#{options[:max]})" if options[:max]
    
    @ingestas << ingesta


end

#to_sObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/Ein/menu.rb', line 99

def to_s
    #aqui tienes q cambiarlo por esto
    #output = "\n #{@dia}" porq si no no te imprime el dia estaras escachando las cosas
    @valor_total = 0
    output = "\n#{@titulo}\n"
    output << "#{@dia} \t\t Composición nutricional \n"
   
    output << "========================================================\n"
    output << "\t\t\tGrasas  Carbohidratos  Proteínas  Fibra  Sal  Valor energético\n"
    output << "Desayuno\n"
    @desayunos.each do |desayuno|
        
        if desayuno[:descripcion] == nil
            desayuno[:descripcion] = "--"
        end
        if desayuno[:grasas] == nil
            desayuno[:grasas] = 0.0
        end
        if desayuno[:carbohidratos] == nil
            desayuno[:carbohidratos] = 0.0
        end
        if desayuno[:proteinas] == nil
            desayuno[:proteinas] = 0.0
        end
        if desayuno[:fibra] == nil
            desayuno[:fibra] = 0.0
        end
        if desayuno[:sal] == nil
            desayuno[:sal] = 0.0
        end
        output << "#{desayuno[:descripcion]}\t"
        output << "#{desayuno[:grasas]} "
        output << "\t   #{desayuno[:carbohidratos]} "
        output << "\t#{desayuno[:proteinas]} "
        output << "\t  #{desayuno[:fibra]} "
        output << "\t#{desayuno[:sal]} "
        output << "\t#{@valor_e_kc_d = ((4.0 * desayuno[:carbohidratos]) + (4.0 * desayuno[:proteinas]) + (9.0 * desayuno[:grasas]) + (6.0 * desayuno[:sal])).round(2)}\n"
        @valor_total += @valor_e_kc_d
    end
    
    output << "\n\nAlmuerzo\n"
    @almuerzos.each do |almuerzo|
        if almuerzo[:descripcion] == nil
            almuerzo[:descripcion] = "--"
        end
        if almuerzo[:grasas] == nil
            almuerzo[:grasas] = 0.0
        end
        if almuerzo[:carbohidratos] == nil
            almuerzo[:carbohidratos] = 0.0
        end
        if almuerzo[:proteinas] == nil
            almuerzo[:proteinas] = 0.0
        end
        if almuerzo[:fibra] == nil
            almuerzo[:fibra] = 0.0
        end
        if almuerzo[:sal] == nil
            almuerzo[:sal] = 0.0
        end
        output << "\n#{almuerzo[:descripcion]} "
        output << "  \t\t #{almuerzo[:grasas]} "
        output << "\t   #{almuerzo[:carbohidratos]} "
        output << "\t#{almuerzo[:proteinas]} "
        output << "\t  #{almuerzo[:fibra]} "
        output << "\t#{almuerzo[:sal]} "
        output << "\t#{@valor_e_kc_a = ((4.0 * almuerzo[:carbohidratos]) + (4.0 * almuerzo[:proteinas]) + (9.0 * almuerzo[:grasas]) + (6.0 * almuerzo[:sal])).round(2)}"
        @valor_total += @valor_e_kc_a
        
    end
    
    
    
    output << "\n\nCena\n"
    @cenas.each do |cena|
        if cena[:descripcion] == nil
            cena[:descripcion] = "--"
        end
        if cena[:grasas] == nil
            cena[:grasas] = 0.0
        end
        if cena[:carbohidratos] == nil
            cena[:carbohidratos] = 0.0
        end
        if cena[:proteinas] == nil
            cena[:proteinas] = 0.0
        end
        if cena[:fibra] == nil
            cena[:fibra] = 0.0
        end
        if cena[:sal] == nil
            cena[:sal] = 0.0
        end
        output << "\n#{cena[:descripcion]} "
        output << "   #{cena[:grasas]} "
        output << "\t   #{cena[:carbohidratos]} "
        output << "\t#{cena[:proteinas]} "
        output << "\t  #{cena[:fibra]} "
        output << "\t#{cena[:sal]} "
        output << "\t#{@valor_e_kc_c = ((4.0 * cena[:carbohidratos]) + (4.0 * cena[:proteinas]) + (9.0 * cena[:grasas]) + (6.0 * cena[:sal])).round(2)}"
        @valor_total += @valor_e_kc_c
    #Tienes q devolver la variable
end
    output << "\nValor energético total"
    output << "\t#{@valor_total}"
    output

end