Class: Dieta_dsl

Inherits:
Object
  • Object
show all
Defined in:
lib/tdd/dietetico_desl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Dieta_dsl

Returns a new instance of Dieta_dsl.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tdd/dietetico_desl.rb', line 4

def initialize(name, &block)
   @dia = name
   @titulo = ""
   @ingesta = []
   @desayuno = []
   @almuerzo = []
   @cena = []


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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



2
3
4
# File 'lib/tdd/dietetico_desl.rb', line 2

def name
  @name
end

Instance Method Details

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



164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/tdd/dietetico_desl.rb', line 164

def almuerzo(name, options={})
    almuerzo = name
    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]
    @almuerzo << almuerzo 
end

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



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/tdd/dietetico_desl.rb', line 177

def cena(name, options={})
    cena = name
    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]
    @cena << cena 
end

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



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/tdd/dietetico_desl.rb', line 151

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

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



142
143
144
145
146
147
148
149
# File 'lib/tdd/dietetico_desl.rb', line 142

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

#kcal_calc(elemento) ⇒ Object



190
191
192
193
# File 'lib/tdd/dietetico_desl.rb', line 190

def kcal_calc(elemento)
    (elemento[:grasas]*9 + elemento[:carbohidratos]*4 + elemento[:proteinas]*4 +elemento[:fibra]*2 + elemento[:sal]*6)/10
    
end

#titulo(title) ⇒ Object



136
137
138
139
140
# File 'lib/tdd/dietetico_desl.rb', line 136

def titulo(title)
    
    @titulo = title
    
end

#to_sObject



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
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
# File 'lib/tdd/dietetico_desl.rb', line 22

def to_s 
    output = "\n #{@titulo}"
    output << "\n ###############################################################################"
    output << "\n #{@dia}\t\t\t\tComposición nutricional"
    output << "\n ==============================================================================="
    output << "\n        \t\t\tgrasas \t carbohidratos \t proteinas \t fibra \t sal \t valor energetico"
    output << "\n Desayuno"
    total_kcal = 0
    @desayuno.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
        output << "\n \"#{elemento[:descripcion]}\""
        output << "\t #{ '%.2f' % elemento[:grasas]}"
        output << "\t\t #{ '%.2f' % elemento[:carbohidratos]}"
        output << "\t #{ '%.2f' % elemento[:proteinas]}"
        output << "\t\t #{ '%.2f' % elemento[:fibra]}"
        output << "\t #{ '%.2f' % elemento[:sal]}"
        output << "\t #{ '%.2f' % kcal_calc(elemento)}"
        total_kcal+=kcal_calc(elemento)
    end
    output << "\n\n\n Almuerzo"
    @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
        output << "\n \"#{elemento[:descripcion]}\""
        output << "\t #{ '%.2f' % elemento[:grasas]}"
        output << "\t\t #{ '%.2f' % elemento[:carbohidratos]}"
        output << "\t #{ '%.2f' % elemento[:proteinas]}"
        output << "\t\t #{ '%.2f' % elemento[:fibra]}"
        output << "\t #{ '%.2f' % elemento[:sal]}"
        output << "\t #{ '%.2f' % kcal_calc(elemento)}"
        total_kcal+=kcal_calc(elemento)
    end
    output << "\n\n\n Cena"
    @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
        output << "\n \"#{elemento[:descripcion]}\""
        output << "\t #{ '%.2f' % elemento[:grasas]}"
        output << "\t\t #{ '%.2f' % elemento[:carbohidratos]}"
        output << "\t #{ '%.2f' % elemento[:proteinas]}"
        output << "\t\t #{ '%.2f' % elemento[:fibra]}"
        output << "\t #{ '%.2f' % elemento[:sal]}"
        output << "\t #{ '%.2f' % kcal_calc(elemento)}"
        total_kcal+=kcal_calc(elemento)
    end
    output << "\n Valor energetico total #{'%.2f' % total_kcal}"
    output
end