tdd-alu0100547160 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +13 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/Guardfile +28 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimento.html +1464 -0
- data/docs/Grupo_de_Alimento.html +650 -0
- data/docs/Lista.html +1136 -0
- data/docs/Nodo.html +409 -0
- data/docs/Tdd.html +117 -0
- data/docs/_index.html +159 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +492 -0
- data/docs/file.README.html +122 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +122 -0
- data/docs/js/app.js +248 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +307 -0
- data/docs/top-level-namespace.html +112 -0
- data/lib/tdd/Alimento.rb +138 -0
- data/lib/tdd/Lista.rb +140 -0
- data/lib/tdd/PlatoHarvard.rb +94 -0
- data/lib/tdd/version.rb +4 -0
- data/lib/tdd.rb +9 -0
- data/tdd.gemspec +41 -0
- metadata +192 -0
@@ -0,0 +1,307 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5
|
+
<meta charset="utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<title>Method List</title>
|
19
|
+
<base id="base_target" target="_parent" />
|
20
|
+
</head>
|
21
|
+
<body>
|
22
|
+
<div id="content">
|
23
|
+
<div class="fixed_header">
|
24
|
+
<h1 id="full_list_header">Method List</h1>
|
25
|
+
<div id="full_list_nav">
|
26
|
+
|
27
|
+
<span><a target="_self" href="class_list.html">
|
28
|
+
Classes
|
29
|
+
</a></span>
|
30
|
+
|
31
|
+
<span><a target="_self" href="method_list.html">
|
32
|
+
Methods
|
33
|
+
</a></span>
|
34
|
+
|
35
|
+
<span><a target="_self" href="file_list.html">
|
36
|
+
Files
|
37
|
+
</a></span>
|
38
|
+
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="search">Search: <input type="text" /></div>
|
42
|
+
</div>
|
43
|
+
|
44
|
+
<ul id="full_list" class="method">
|
45
|
+
|
46
|
+
|
47
|
+
<li class="odd ">
|
48
|
+
<div class="item">
|
49
|
+
<span class='object_link'><a href="Alimento.html#<=>-instance_method" title="Alimento#<=> (method)">#<=></a></span>
|
50
|
+
<small>Alimento</small>
|
51
|
+
</div>
|
52
|
+
</li>
|
53
|
+
|
54
|
+
|
55
|
+
<li class="even ">
|
56
|
+
<div class="item">
|
57
|
+
<span class='object_link'><a href="Grupo_de_Alimento.html#<=>-instance_method" title="Grupo_de_Alimento#<=> (method)">#<=></a></span>
|
58
|
+
<small>Grupo_de_Alimento</small>
|
59
|
+
</div>
|
60
|
+
</li>
|
61
|
+
|
62
|
+
|
63
|
+
<li class="odd ">
|
64
|
+
<div class="item">
|
65
|
+
<span class='object_link'><a href="Grupo_de_Alimento.html#==-instance_method" title="Grupo_de_Alimento#== (method)">#==</a></span>
|
66
|
+
<small>Grupo_de_Alimento</small>
|
67
|
+
</div>
|
68
|
+
</li>
|
69
|
+
|
70
|
+
|
71
|
+
<li class="even ">
|
72
|
+
<div class="item">
|
73
|
+
<span class='object_link'><a href="Nodo.html#Next_-instance_method" title="Nodo#Next_ (method)">#Next_</a></span>
|
74
|
+
<small>Nodo</small>
|
75
|
+
</div>
|
76
|
+
</li>
|
77
|
+
|
78
|
+
|
79
|
+
<li class="odd ">
|
80
|
+
<div class="item">
|
81
|
+
<span class='object_link'><a href="Lista.html#cabeza-instance_method" title="Lista#cabeza (method)">#cabeza</a></span>
|
82
|
+
<small>Lista</small>
|
83
|
+
</div>
|
84
|
+
</li>
|
85
|
+
|
86
|
+
|
87
|
+
<li class="even ">
|
88
|
+
<div class="item">
|
89
|
+
<span class='object_link'><a href="Lista.html#cola-instance_method" title="Lista#cola (method)">#cola</a></span>
|
90
|
+
<small>Lista</small>
|
91
|
+
</div>
|
92
|
+
</li>
|
93
|
+
|
94
|
+
|
95
|
+
<li class="odd ">
|
96
|
+
<div class="item">
|
97
|
+
<span class='object_link'><a href="Lista.html#each-instance_method" title="Lista#each (method)">#each</a></span>
|
98
|
+
<small>Lista</small>
|
99
|
+
</div>
|
100
|
+
</li>
|
101
|
+
|
102
|
+
|
103
|
+
<li class="even ">
|
104
|
+
<div class="item">
|
105
|
+
<span class='object_link'><a href="Alimento.html#each-instance_method" title="Alimento#each (method)">#each</a></span>
|
106
|
+
<small>Alimento</small>
|
107
|
+
</div>
|
108
|
+
</li>
|
109
|
+
|
110
|
+
|
111
|
+
<li class="odd ">
|
112
|
+
<div class="item">
|
113
|
+
<span class='object_link'><a href="Grupo_de_Alimento.html#each-instance_method" title="Grupo_de_Alimento#each (method)">#each</a></span>
|
114
|
+
<small>Grupo_de_Alimento</small>
|
115
|
+
</div>
|
116
|
+
</li>
|
117
|
+
|
118
|
+
|
119
|
+
<li class="even ">
|
120
|
+
<div class="item">
|
121
|
+
<span class='object_link'><a href="Lista.html#extraer_delante-instance_method" title="Lista#extraer_delante (method)">#extraer_delante</a></span>
|
122
|
+
<small>Lista</small>
|
123
|
+
</div>
|
124
|
+
</li>
|
125
|
+
|
126
|
+
|
127
|
+
<li class="odd ">
|
128
|
+
<div class="item">
|
129
|
+
<span class='object_link'><a href="Lista.html#extraer_detras-instance_method" title="Lista#extraer_detras (method)">#extraer_detras</a></span>
|
130
|
+
<small>Lista</small>
|
131
|
+
</div>
|
132
|
+
</li>
|
133
|
+
|
134
|
+
|
135
|
+
<li class="even ">
|
136
|
+
<div class="item">
|
137
|
+
<span class='object_link'><a href="Alimento.html#get_glucidos-instance_method" title="Alimento#get_glucidos (method)">#get_glucidos</a></span>
|
138
|
+
<small>Alimento</small>
|
139
|
+
</div>
|
140
|
+
</li>
|
141
|
+
|
142
|
+
|
143
|
+
<li class="odd ">
|
144
|
+
<div class="item">
|
145
|
+
<span class='object_link'><a href="Alimento.html#get_grasas-instance_method" title="Alimento#get_grasas (method)">#get_grasas</a></span>
|
146
|
+
<small>Alimento</small>
|
147
|
+
</div>
|
148
|
+
</li>
|
149
|
+
|
150
|
+
|
151
|
+
<li class="even ">
|
152
|
+
<div class="item">
|
153
|
+
<span class='object_link'><a href="Alimento.html#get_nombre-instance_method" title="Alimento#get_nombre (method)">#get_nombre</a></span>
|
154
|
+
<small>Alimento</small>
|
155
|
+
</div>
|
156
|
+
</li>
|
157
|
+
|
158
|
+
|
159
|
+
<li class="odd ">
|
160
|
+
<div class="item">
|
161
|
+
<span class='object_link'><a href="Alimento.html#get_proteinas-instance_method" title="Alimento#get_proteinas (method)">#get_proteinas</a></span>
|
162
|
+
<small>Alimento</small>
|
163
|
+
</div>
|
164
|
+
</li>
|
165
|
+
|
166
|
+
|
167
|
+
<li class="even ">
|
168
|
+
<div class="item">
|
169
|
+
<span class='object_link'><a href="Alimento.html#get_valor_energetico-instance_method" title="Alimento#get_valor_energetico (method)">#get_valor_energetico</a></span>
|
170
|
+
<small>Alimento</small>
|
171
|
+
</div>
|
172
|
+
</li>
|
173
|
+
|
174
|
+
|
175
|
+
<li class="odd ">
|
176
|
+
<div class="item">
|
177
|
+
<span class='object_link'><a href="Alimento.html#glucidos-instance_method" title="Alimento#glucidos (method)">#glucidos</a></span>
|
178
|
+
<small>Alimento</small>
|
179
|
+
</div>
|
180
|
+
</li>
|
181
|
+
|
182
|
+
|
183
|
+
<li class="even ">
|
184
|
+
<div class="item">
|
185
|
+
<span class='object_link'><a href="Alimento.html#grasas-instance_method" title="Alimento#grasas (method)">#grasas</a></span>
|
186
|
+
<small>Alimento</small>
|
187
|
+
</div>
|
188
|
+
</li>
|
189
|
+
|
190
|
+
|
191
|
+
<li class="odd ">
|
192
|
+
<div class="item">
|
193
|
+
<span class='object_link'><a href="Grupo_de_Alimento.html#grupo-instance_method" title="Grupo_de_Alimento#grupo (method)">#grupo</a></span>
|
194
|
+
<small>Grupo_de_Alimento</small>
|
195
|
+
</div>
|
196
|
+
</li>
|
197
|
+
|
198
|
+
|
199
|
+
<li class="even ">
|
200
|
+
<div class="item">
|
201
|
+
<span class='object_link'><a href="Lista.html#initialize-instance_method" title="Lista#initialize (method)">#initialize</a></span>
|
202
|
+
<small>Lista</small>
|
203
|
+
</div>
|
204
|
+
</li>
|
205
|
+
|
206
|
+
|
207
|
+
<li class="odd ">
|
208
|
+
<div class="item">
|
209
|
+
<span class='object_link'><a href="Alimento.html#initialize-instance_method" title="Alimento#initialize (method)">#initialize</a></span>
|
210
|
+
<small>Alimento</small>
|
211
|
+
</div>
|
212
|
+
</li>
|
213
|
+
|
214
|
+
|
215
|
+
<li class="even ">
|
216
|
+
<div class="item">
|
217
|
+
<span class='object_link'><a href="Grupo_de_Alimento.html#initialize-instance_method" title="Grupo_de_Alimento#initialize (method)">#initialize</a></span>
|
218
|
+
<small>Grupo_de_Alimento</small>
|
219
|
+
</div>
|
220
|
+
</li>
|
221
|
+
|
222
|
+
|
223
|
+
<li class="odd ">
|
224
|
+
<div class="item">
|
225
|
+
<span class='object_link'><a href="Lista.html#insertar_delante-instance_method" title="Lista#insertar_delante (method)">#insertar_delante</a></span>
|
226
|
+
<small>Lista</small>
|
227
|
+
</div>
|
228
|
+
</li>
|
229
|
+
|
230
|
+
|
231
|
+
<li class="even ">
|
232
|
+
<div class="item">
|
233
|
+
<span class='object_link'><a href="Lista.html#insertar_detras-instance_method" title="Lista#insertar_detras (method)">#insertar_detras</a></span>
|
234
|
+
<small>Lista</small>
|
235
|
+
</div>
|
236
|
+
</li>
|
237
|
+
|
238
|
+
|
239
|
+
<li class="odd ">
|
240
|
+
<div class="item">
|
241
|
+
<span class='object_link'><a href="Alimento.html#nombre-instance_method" title="Alimento#nombre (method)">#nombre</a></span>
|
242
|
+
<small>Alimento</small>
|
243
|
+
</div>
|
244
|
+
</li>
|
245
|
+
|
246
|
+
|
247
|
+
<li class="even ">
|
248
|
+
<div class="item">
|
249
|
+
<span class='object_link'><a href="Nodo.html#prev-instance_method" title="Nodo#prev (method)">#prev</a></span>
|
250
|
+
<small>Nodo</small>
|
251
|
+
</div>
|
252
|
+
</li>
|
253
|
+
|
254
|
+
|
255
|
+
<li class="odd ">
|
256
|
+
<div class="item">
|
257
|
+
<span class='object_link'><a href="Alimento.html#proteinas-instance_method" title="Alimento#proteinas (method)">#proteinas</a></span>
|
258
|
+
<small>Alimento</small>
|
259
|
+
</div>
|
260
|
+
</li>
|
261
|
+
|
262
|
+
|
263
|
+
<li class="even ">
|
264
|
+
<div class="item">
|
265
|
+
<span class='object_link'><a href="Lista.html#tam-instance_method" title="Lista#tam (method)">#tam</a></span>
|
266
|
+
<small>Lista</small>
|
267
|
+
</div>
|
268
|
+
</li>
|
269
|
+
|
270
|
+
|
271
|
+
<li class="odd ">
|
272
|
+
<div class="item">
|
273
|
+
<span class='object_link'><a href="Lista.html#to_s-instance_method" title="Lista#to_s (method)">#to_s</a></span>
|
274
|
+
<small>Lista</small>
|
275
|
+
</div>
|
276
|
+
</li>
|
277
|
+
|
278
|
+
|
279
|
+
<li class="even ">
|
280
|
+
<div class="item">
|
281
|
+
<span class='object_link'><a href="Alimento.html#to_s-instance_method" title="Alimento#to_s (method)">#to_s</a></span>
|
282
|
+
<small>Alimento</small>
|
283
|
+
</div>
|
284
|
+
</li>
|
285
|
+
|
286
|
+
|
287
|
+
<li class="odd ">
|
288
|
+
<div class="item">
|
289
|
+
<span class='object_link'><a href="Grupo_de_Alimento.html#to_s-instance_method" title="Grupo_de_Alimento#to_s (method)">#to_s</a></span>
|
290
|
+
<small>Grupo_de_Alimento</small>
|
291
|
+
</div>
|
292
|
+
</li>
|
293
|
+
|
294
|
+
|
295
|
+
<li class="even ">
|
296
|
+
<div class="item">
|
297
|
+
<span class='object_link'><a href="Nodo.html#value-instance_method" title="Nodo#value (method)">#value</a></span>
|
298
|
+
<small>Nodo</small>
|
299
|
+
</div>
|
300
|
+
</li>
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
</ul>
|
305
|
+
</div>
|
306
|
+
</body>
|
307
|
+
</html>
|
@@ -0,0 +1,112 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.9
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "";
|
19
|
+
relpath = '';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="_index.html">Index</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">Top Level Namespace</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Top Level Namespace
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
</div>
|
80
|
+
|
81
|
+
<h2>Defined Under Namespace</h2>
|
82
|
+
<p class="children">
|
83
|
+
|
84
|
+
|
85
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Tdd.html" title="Tdd (module)">Tdd</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Alimento.html" title="Alimento (class)">Alimento</a></span>, <span class='object_link'><a href="Grupo_de_Alimento.html" title="Grupo_de_Alimento (class)">Grupo_de_Alimento</a></span>, <span class='object_link'><a href="Lista.html" title="Lista (class)">Lista</a></span>, <span class='object_link'><a href="Nodo.html" title="Nodo (class)">Nodo</a></span>
|
90
|
+
|
91
|
+
|
92
|
+
</p>
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<div id="footer">
|
105
|
+
Generated on Wed Nov 15 03:29:44 2017 by
|
106
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
|
+
0.9.9 (ruby-2.3.4).
|
108
|
+
</div>
|
109
|
+
|
110
|
+
</div>
|
111
|
+
</body>
|
112
|
+
</html>
|
data/lib/tdd/Alimento.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#require '/home/ubuntu/workspace/p6/tdd/lib/tdd/Lista.rb'
|
2
|
+
# Clase ALimento , Plantilla para representar un alimento
|
3
|
+
# con sus respectivo nombre e información sobre nutrientes
|
4
|
+
# @author Lisseth Vergaray Del Aguila
|
5
|
+
class Alimento
|
6
|
+
#Módulo comparable que se incluye para hacer uso de sus utulidades
|
7
|
+
include Comparable
|
8
|
+
# @return [String] nombre del alimento
|
9
|
+
# @return [Numeric] proteinas que contiene el alimento
|
10
|
+
# @return [Numeric] glúcidos que contiene el alimento
|
11
|
+
# @return [Numeric] grasas que contiene el alimento
|
12
|
+
attr_accessor :nombre, :proteinas, :glucidos, :grasas, :g
|
13
|
+
|
14
|
+
# Método para inicializar el objeto
|
15
|
+
# @param nombre proteinas glucidos grasas
|
16
|
+
def initialize (nombre, proteinas, glucidos, grasas, g)
|
17
|
+
@nombre = nombre
|
18
|
+
@proteinas = proteinas
|
19
|
+
@glucidos = glucidos
|
20
|
+
@grasas = grasas
|
21
|
+
@g = g
|
22
|
+
end
|
23
|
+
# Getter de atributo nombre
|
24
|
+
# @return nombre
|
25
|
+
def get_nombre
|
26
|
+
@nombre
|
27
|
+
end
|
28
|
+
# Getter de atributo proteínas
|
29
|
+
# @return proteinas
|
30
|
+
def get_proteinas
|
31
|
+
@proteinas
|
32
|
+
end
|
33
|
+
# Getter de atributo glúcidos
|
34
|
+
# @return glucidos
|
35
|
+
def get_glucidos
|
36
|
+
@glucidos
|
37
|
+
end
|
38
|
+
# Getter de atributo grasas
|
39
|
+
# @return grasas
|
40
|
+
def get_grasas
|
41
|
+
@grasas
|
42
|
+
end
|
43
|
+
# Método para mostrar el objeto
|
44
|
+
# @return cadena s
|
45
|
+
def to_s
|
46
|
+
s = ""
|
47
|
+
# s << "#{@nombre} #{@proteinas} #{@glucidos} #{@grasas}"
|
48
|
+
printf("%18s %10s %10s %10s %10s"," #{@nombre}","#{@proteinas}"," #{@glucidos}","#{@grasas}","#{get_valor_energetico}");
|
49
|
+
|
50
|
+
# s << "#{self.get_valor_energetico}"
|
51
|
+
end
|
52
|
+
# Restrictivo (con herencia - usa is_a?)
|
53
|
+
def ==(other)
|
54
|
+
if other.is_a?Alimento
|
55
|
+
@nombre == other.nombre && @proteinas == other.proteinas && @glucidos == other.glucidos && @grasas = other.grasas
|
56
|
+
else
|
57
|
+
false
|
58
|
+
end
|
59
|
+
end
|
60
|
+
# Método <=> para Mixin de Comparable
|
61
|
+
# @param otro , recibe otro objeto Alimento para compararse
|
62
|
+
def <=>(otro)
|
63
|
+
if otro.is_a?Alimento
|
64
|
+
self.get_valor_energetico <=> otro.get_valor_energetico
|
65
|
+
end
|
66
|
+
end
|
67
|
+
#Método each para poder hacer uso de Enumerable
|
68
|
+
# def each
|
69
|
+
# yield @nombre
|
70
|
+
# yield @proteinas
|
71
|
+
# yield @glucidos
|
72
|
+
# yield @grasas
|
73
|
+
# yield self.get_valor_energetico
|
74
|
+
# end
|
75
|
+
# Método para calcular el valor enérgetico del ALimento
|
76
|
+
# @return ve
|
77
|
+
def get_valor_energetico
|
78
|
+
ve = ((@proteinas * 4) + (@glucidos * 4) + (@grasas * 9))
|
79
|
+
ve.round(3)
|
80
|
+
end
|
81
|
+
# Método para calcular aibc de dos individuos
|
82
|
+
# @return suma que es un vector con el sumatorio de los indices
|
83
|
+
def aibc
|
84
|
+
r = []
|
85
|
+
(0..g.size - 1).map { |i|
|
86
|
+
s = []
|
87
|
+
(1..g[i].size-1).map { |m|
|
88
|
+
if g[i][m] < g[i][0]
|
89
|
+
s << 0.0
|
90
|
+
else
|
91
|
+
s << (((g[i][m] - g[i][0]) + (g[i][m-1] - g[i][0]))/2)*5
|
92
|
+
end
|
93
|
+
}
|
94
|
+
r << s
|
95
|
+
}
|
96
|
+
suma = []
|
97
|
+
(0..g.size-1).collect { |e|
|
98
|
+
s = 0
|
99
|
+
(0..r[e].size-1).map { |k|
|
100
|
+
s = s + r[e][k]
|
101
|
+
}
|
102
|
+
suma << s
|
103
|
+
}
|
104
|
+
suma
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Clase Grupo_de_Alimento que hereda de Alimento
|
109
|
+
# @author Lisseth Vergaray
|
110
|
+
class Grupo_de_Alimento < Alimento
|
111
|
+
# @return [String] grupo de alimento
|
112
|
+
attr_reader :grupo
|
113
|
+
# Método para inicializar el objeto
|
114
|
+
def initialize(grupo, nombre, proteinas, glucidos, grasas,g )
|
115
|
+
@grupo = grupo
|
116
|
+
super(nombre, proteinas, glucidos, grasas,g) #encadenamiento (chaining)
|
117
|
+
end
|
118
|
+
#Encadenamiento (chaining)
|
119
|
+
def to_s
|
120
|
+
#s = "#{@grupo} "
|
121
|
+
s = " "
|
122
|
+
s << super.to_s
|
123
|
+
end
|
124
|
+
#Restrictivo (con herencia - usa is_a?)
|
125
|
+
# def ==(other)
|
126
|
+
# if other.is_a?Grupo_de_Alimento
|
127
|
+
# @grupo == other.grupo && @nombre == other.nombre && @proteinas == other.proteinas && @glucidos == other.glucidos && @grasas = other.grasas
|
128
|
+
# else
|
129
|
+
# false
|
130
|
+
# end
|
131
|
+
# end
|
132
|
+
#Definiendo <=> para el Mixin de Comporable
|
133
|
+
def <=>(otro)
|
134
|
+
if otro.is_a?Grupo_de_Alimento
|
135
|
+
self.get_valor_energetico <=> otro.get_valor_energetico
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
data/lib/tdd/Lista.rb
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
#Struct de un nodo para insertar en lista
|
2
|
+
Nodo = Struct.new(:value, :Next_, :prev)
|
3
|
+
# Clase Lista , es una lista doblemente enlazada
|
4
|
+
# @author Lisseth Vergaray Del Aguila
|
5
|
+
class Lista
|
6
|
+
#Módulo Enumerable para sort, map, collect, etc
|
7
|
+
include Enumerable
|
8
|
+
# @return [Numeric] el tamaño de la lista
|
9
|
+
# @return [Pointer] el puntero cabeza de lista
|
10
|
+
# @return [Pointer] el puntero cola de lista
|
11
|
+
attr_accessor :tam, :cabeza, :cola
|
12
|
+
def initialize()
|
13
|
+
@tam = 0
|
14
|
+
@cabeza = nil
|
15
|
+
@cola = nil
|
16
|
+
end
|
17
|
+
# Inserta un nodo por la cabeza de la lista
|
18
|
+
# @param dato [Value] será el campo value del nodo
|
19
|
+
def insertar_delante(dato)
|
20
|
+
dato_ = Nodo.new(dato,nil,nil)
|
21
|
+
if (tam == 0)
|
22
|
+
@cola = dato_
|
23
|
+
@cabeza = dato_
|
24
|
+
|
25
|
+
else
|
26
|
+
dato_[:Next_] = @cabeza #|nil|cabeza/dato|nil
|
27
|
+
@cabeza.prev = dato_
|
28
|
+
dato_[:prev] = nil
|
29
|
+
@cabeza = dato_
|
30
|
+
|
31
|
+
end
|
32
|
+
@tam = @tam + 1
|
33
|
+
|
34
|
+
end
|
35
|
+
# Inserta por la cola y aunmenta tamaño de lista
|
36
|
+
# @param dato [Value] será el campo value del nodo
|
37
|
+
def insertar_detras(dato)
|
38
|
+
dato_ = Nodo.new(dato,nil,nil)
|
39
|
+
if (@tam == 0)
|
40
|
+
@cabeza = dato_
|
41
|
+
@cola = dato_
|
42
|
+
else
|
43
|
+
dato_[:prev] = @cola
|
44
|
+
@cola[:Next_]= dato_
|
45
|
+
dato_[:Next_] = nil
|
46
|
+
@cola = dato_
|
47
|
+
end
|
48
|
+
|
49
|
+
@tam = @tam + 1
|
50
|
+
end
|
51
|
+
# Extraer un elemento por la cabeza
|
52
|
+
# @return aux retorna el campo value del nodo
|
53
|
+
def extraer_delante
|
54
|
+
if(@tam == 0)
|
55
|
+
puts "La Lista está vacía"
|
56
|
+
else
|
57
|
+
aux = @cabeza
|
58
|
+
@cabeza = @cabeza[:Next_]
|
59
|
+
@cabeza[:prev] = nil
|
60
|
+
@tam = @tam - 1
|
61
|
+
return aux[:value]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
#Extraer un elemento por la cola
|
65
|
+
# @return aux retorna el campo value del nodo
|
66
|
+
def extraer_detras
|
67
|
+
if(@tam == 0)
|
68
|
+
puts "La Lista está vacía"
|
69
|
+
else
|
70
|
+
aux = @cola
|
71
|
+
@cola = @cola[:prev]
|
72
|
+
@cola[:Next_] = nil
|
73
|
+
@tam = @tam - 1
|
74
|
+
return aux[:value]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
#Mostrar la lista
|
78
|
+
def to_s
|
79
|
+
aux = @cabeza
|
80
|
+
while(aux != nil)
|
81
|
+
puts aux.value
|
82
|
+
aux = aux.Next_
|
83
|
+
end
|
84
|
+
end
|
85
|
+
# Método de ordenación de lista
|
86
|
+
def sort_lista
|
87
|
+
# @lista_ordenada = Lista.new()
|
88
|
+
# self.each{|i| @lista_ordenada.insertar_detras(i)}.sort{ |a,b| a <=> b}
|
89
|
+
|
90
|
+
end
|
91
|
+
# Método de acceso a acada elemento con Enumerable
|
92
|
+
def each
|
93
|
+
aux = @cabeza
|
94
|
+
while(aux != nil)
|
95
|
+
yield aux[:value]
|
96
|
+
aux= aux[:Next_]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def find (nombre)
|
101
|
+
aux = @cabeza
|
102
|
+
while(aux != nil)
|
103
|
+
if (nombre == aux.value)
|
104
|
+
return aux
|
105
|
+
else
|
106
|
+
aux = aux.Next_
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
@nodo1 = Nodo.new("Platano",nil,nil)
|
118
|
+
#@nodo2 = Nodo.new(8,nil,nil)
|
119
|
+
# @nodo3 = Nodo.new(9,nil,nil)
|
120
|
+
@lista = Lista.new()
|
121
|
+
@lista.insertar_delante(@nodo1)
|
122
|
+
s = @lista.find("Platano")
|
123
|
+
puts s
|
124
|
+
# @lista.insertar_detras(5)
|
125
|
+
# @lista.insertar_detras(8)
|
126
|
+
# @lista.insertar_detras(15)
|
127
|
+
# @lista.insertar_delante(3)
|
128
|
+
# @lista.to_s
|
129
|
+
# s = @lista.extraer_delante
|
130
|
+
# puts s
|
131
|
+
# s = @lista.extraer_detras
|
132
|
+
# puts s
|
133
|
+
# puts @lista.to_s
|
134
|
+
# # @lista.to_s
|
135
|
+
# # @lista.extraer_detras
|
136
|
+
# # @lista.to_s
|
137
|
+
# # @lista.insertar_delante
|
138
|
+
# # @lista.to_s
|
139
|
+
|
140
|
+
|