Class: Menu

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &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
24
25
# File 'lib/prct06/menu.rb', line 6

def initialize(name, &block)
 
		@desayuno_array = []
		@almuerzo = []
 		@cena = []
 		@titulo
 		@ingesta = []
 		@name = name
 		@ingredients = []
 		@instructions = []
 		@valor_energetico = 0

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

Instance Attribute Details

#ingredientsObject

Returns the value of attribute ingredients.



4
5
6
# File 'lib/prct06/menu.rb', line 4

def ingredients
  @ingredients
end

#instructionsObject

Returns the value of attribute instructions.



4
5
6
# File 'lib/prct06/menu.rb', line 4

def instructions
  @instructions
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/prct06/menu.rb', line 4

def name
  @name
end

Instance Method Details

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



194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/prct06/menu.rb', line 194

def almuerzo(name,options = {})
   		almuerzo = name
   		almuerzo << "(#{options[:descripcion]}" if options[:descripcion]
   		almuerzo << "(#{options[:porcion]}" if options[:porcion]
   		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]

   		@almuerzo << almuerzo
end

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



208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/prct06/menu.rb', line 208

def cena(name, options = {})
  		cena = name 
  		cena << "(#{options[:descripcion]}" if options[:descripcion]
  		cena << "(#{options[:porcion]}" if options[:porcion]
  		cena << "(#{options[:gramo]}" if options[:gramo]
  		cena << "(#{options[:grasa]}" if options[:grasa]
  		cena << "(#{options[:proteina]}" if options[:proteina]
  		cena << "(#{options[:carbohidratos]}" if options[:carbohidratos]
  		cena << "(#{options[:sal]}" if options[:sal]

  		@cena << cena
end

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



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/prct06/menu.rb', line 176

def desayuno(name, options = {})
       
	desayuno = name
       	desayuno << "(#{options[:descripcion]}" if options[:descripcion]
       	desayuno << "(#{options[:porcion]}" if options[:porcion]
       	desayuno << "(#{options[:grasas]}" if options[:grasas]
       	desayuno << "(#{options[:gramos]}" if options[:gramos]
       	desayuno << "(#{options[:carbohidratos]}" if options[:carbohidratos]
       	desayuno << "(#{options[:proteinas]}" if options[:proteinas]
       	desayuno << "(#{options[:fibra]}" if options[:fibra]
       	desayuno << "(#{options[:sal]}" if options[:sal]

       	@desayuno_array << desayuno
 
end

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



167
168
169
170
171
172
173
# File 'lib/prct06/menu.rb', line 167

def ingesta(name,options = {})
 		ingesta = name
 		ingesta << "(#{options[:min]}" if options[:min]
 		ingesta << "(#{options[:max]}" if options[:max] 

 		@ingesta << ingesta
end

#titulo(name) ⇒ Object



162
163
164
# File 'lib/prct06/menu.rb', line 162

def titulo(name)
   	@titulo = name
end

#to_sObject



28
29
30
31
32
33
34
35
36
37
38
39
40
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
# File 'lib/prct06/menu.rb', line 28

def to_s

   		puts @name
   		puts "\t \t \t Composición nutricional"
   		puts "\n#{'=' *100}\n\n"
   		puts "\t \t \t Grasa \t Carbohidratos \t Proteinas \t fibra \t sal \t valor energético \n \n "

   		@valor_total = 0

   		@desayuno_array.each do |elemento|
       		if elemento[:descripcion] == nil
       	    		elemento[:descripcion] = 0.00
       		end
       		
		if elemento[:fibra] == nil
           			elemento[:fibra] = 0.00
       		end
       		
		if elemento[:grasas] == nil
           			elemento[:grasas] = 0.00
       		end
       		if elemento[:carbohidratos] == nil
           			elemento[:carbohidratos] = 0.00
       		end
       
		if elemento[:proteinas] == nil
           			elemento[:proteinas] = 0.00
       		end
       
		if elemento[:sal] == nil
           			elemento[:sal] = 0.00
       		end
       
		print elemento[:descripcion]
		        print "\t  #{elemento[:grasas]}"
       		print "\t   #{elemento[:carbohidratos]}"
       		print "\t \t #{elemento[:proteinas]}"
       		print "\t \t  #{elemento[:fibra]}"
       		print "\t  #{elemento[:sal]}"
       		print "\t  #{@valor_energetico = (elemento[:grasas]*9 + elemento[:carbohidratos]*4 + elemento[:proteinas]*4 +elemento[:fibra]*2 + elemento[:sal]*6)/10}"
       
		puts 
       		@valor_total += @valor_energetico
   
	end

   
	@almuerzo.each do |elemento|
       		if elemento[:descripcion] == nil
           			elemento[:descripcion] = 0.00
       		end
		
       		if elemento[:fibra] == nil
           			elemento[:fibra] = 0.00
       		end
       
		if elemento[:grasas] == nil
           			elemento[:grasas] = 0.00
       		end
       
		if elemento[:carbohidratos] == nil
           			elemento[:carbohidratos] = 0.00
       		end
       
		if elemento[:proteinas] == nil
           			elemento[:proteinas] = 0.00
       		end
       		
		if elemento[:sal] == nil
           			elemento[:sal] = 0.00
       		end

       		print "#{elemento[:descripcion]}" 
       		print  "\t \t #{elemento[:grasas]}"
       		print  "\t #{elemento[:carbohidratos]}"
       		print  "\t \t#{elemento[:proteinas]}"
       		print  "\t \t#{elemento[:fibra]}"
       		print  "\t #{elemento[:sal]}"
       		print "\t #{@valor_energetico = (elemento[:grasas]*9 + elemento[:carbohidratos]*4 + elemento[:proteinas]*4 +elemento[:fibra]*2 + elemento[:sal]*6)/10}"
       
		puts
       		@valor_total += @valor_energetico
   
	end

	@cena.each do |elemento|
       		if elemento[:descripcion] == nil
           			elemento[:descripcion] = 0.00
       		end
       
		if elemento[:fibra] == nil
           			elemento[:fibra] = 0.00
       		end
       
		if elemento[:grasas] == nil
           			elemento[:grasas] = 0.00
       		end
       
		if elemento[:carbohidratos] == nil
           			elemento[:carbohidratos] = 0.00
		end
       		
		if elemento[:proteinas] == nil
           			elemento[:proteinas] = 0.00
       		end
       
		if elemento[:sal] == nil
           			elemento[:sal] = 0.00
       		end
       		
		print elemento[:descripcion]
       		print " \t  #{elemento[:grasas]}"
       		print " \t #{elemento[:carbohidratos]}"
       		print "\t \t #{elemento[:proteinas]}"
       		print "\t \t #{elemento[:fibra]}"
       		print "\t #{elemento[:sal]}"
       		print " \t #{@valor_energetico = (elemento[:grasas]*9 + elemento[:carbohidratos]*4 + elemento[:proteinas]*4 +elemento[:fibra]*2 + elemento[:sal]*6)/10}"
       	
		puts 
       		@valor_total += @valor_energetico
   
	end
      
       	print "Valor energético total #{@valor_total}" 
       	puts
       	puts
       	puts
       	puts
       	puts
       	puts "\n#{'=' *100}\n\n"

end