alimento0100997910 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +8 -0
- data/.rspec +1 -0
- data/.rspec_status +55 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/Guardfile +82 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/alimento.gemspec +40 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimento.html +150 -0
- data/docs/Alimento/Alimento.html +961 -0
- data/docs/Alimento/Carbohidratos.html +240 -0
- data/docs/Alimento/Carnes.html +239 -0
- data/docs/Alimento/DerivadoLacteo.html +239 -0
- data/docs/Alimento/Frutas.html +239 -0
- data/docs/Alimento/Grasos.html +240 -0
- data/docs/Alimento/Pescados.html +239 -0
- data/docs/Alimento/Plato.html +1178 -0
- data/docs/Alimento/Verduras.html +239 -0
- data/docs/Lista.html +139 -0
- data/docs/Lista/Lista.html +858 -0
- data/docs/Lista/Lista/Node.html +398 -0
- data/docs/_index.html +256 -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 +117 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +117 -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 +379 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/alimento.rb +10 -0
- data/lib/alimento/fuente.rb +424 -0
- data/lib/alimento/version.rb +3 -0
- metadata +198 -0
@@ -0,0 +1,110 @@
|
|
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="Alimento.html" title="Alimento (module)">Alimento</a></span>, <span class='object_link'><a href="Lista.html" title="Lista (module)">Lista</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</p>
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
</div>
|
101
|
+
|
102
|
+
<div id="footer">
|
103
|
+
Generated on Tue Dec 12 20:42:59 2017 by
|
104
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
|
+
0.9.9 (ruby-2.4.2).
|
106
|
+
</div>
|
107
|
+
|
108
|
+
</div>
|
109
|
+
</body>
|
110
|
+
</html>
|
data/lib/alimento.rb
ADDED
@@ -0,0 +1,424 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Este módulo se ha creado para describir
|
3
|
+
# las clases alimentos y las clases que heredan de los alimentos
|
4
|
+
# Author:: Alejandro González Alonso (mailto:alu0100997910@ull.edu.es)
|
5
|
+
# Copyright:: Creative Commons
|
6
|
+
# License:: Distributes under the same terms as Ruby
|
7
|
+
|
8
|
+
module Alimento
|
9
|
+
# Esta clase permite representar un alimento, con sus valores
|
10
|
+
# en Proteínas, Glúcidos y Lípidos
|
11
|
+
# Se han incluido los mixin Comparable.
|
12
|
+
class Alimento
|
13
|
+
include Comparable
|
14
|
+
attr_reader :nombre, :proteinas, :glucidos, :lipidos
|
15
|
+
|
16
|
+
# Se define para incluir el mixin comparable
|
17
|
+
# Compara los alimentos según su valor energético
|
18
|
+
def <=>(other)
|
19
|
+
return nil unless other.kind_of?Alimento
|
20
|
+
self.energeticValue <=> other.energeticValue
|
21
|
+
end
|
22
|
+
|
23
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
24
|
+
# y el nombre del alimento
|
25
|
+
def initialize(name,p,g,l,med=nil)
|
26
|
+
@nombre=name
|
27
|
+
@proteinas=p
|
28
|
+
@glucidos=g
|
29
|
+
@lipidos=l
|
30
|
+
@g=med
|
31
|
+
end
|
32
|
+
|
33
|
+
# Se calcula el valor energético del alimento
|
34
|
+
def energeticValue
|
35
|
+
value = @proteinas*4 + @glucidos*4 + @lipidos*9
|
36
|
+
end
|
37
|
+
|
38
|
+
# Calcula el area bajo la curva de un alimento
|
39
|
+
def aibc
|
40
|
+
aibc=[]
|
41
|
+
@g.each do |value|
|
42
|
+
s=[]
|
43
|
+
value.each_with_index do |val,j|
|
44
|
+
if (j!=0)
|
45
|
+
s << (((val-value[0])+(value[j-1]-value[0]))*5)/2
|
46
|
+
end
|
47
|
+
end
|
48
|
+
aibc << s.reduce(:+)
|
49
|
+
end
|
50
|
+
aibc
|
51
|
+
end
|
52
|
+
|
53
|
+
# Calcula el indice glucemico individual de un alimento
|
54
|
+
def indIdv(individuo,glucosa)
|
55
|
+
indidv=self.aibc[individuo]*100/glucosa.aibc[individuo]
|
56
|
+
end
|
57
|
+
|
58
|
+
# Calcula el indice glucemico total de un alimento
|
59
|
+
def indGlu(glucosa)
|
60
|
+
indidv=[]
|
61
|
+
@g.each_with_index do |value,index|
|
62
|
+
indidv << indIdv(index,glucosa)
|
63
|
+
end
|
64
|
+
(indidv.reduce(:+))/@g.size
|
65
|
+
end
|
66
|
+
|
67
|
+
# Formatea el objeto alimento a una cadena de texto
|
68
|
+
def to_s
|
69
|
+
cadena = "[#{@nombre},#{@proteinas},#{@glucidos},#{@lipidos}]"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
# Esta clase permite representar un alimento que es derivado lacteo
|
73
|
+
class DerivadoLacteo < Alimento
|
74
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
75
|
+
# y el nombre del alimento a través del initialize de la superclass
|
76
|
+
# y se define el nombre de la categoria
|
77
|
+
def initialize(name,p,g,l)
|
78
|
+
super(name,p,g,l)
|
79
|
+
@categoria="Huevos, Lacteos y Helados"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Esta clase permite representar un alimento en la categoria de carnes
|
84
|
+
class Carnes < Alimento
|
85
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
86
|
+
# y el nombre del alimento a través del initialize de la superclass
|
87
|
+
# y se define el nombre de la categoria
|
88
|
+
def initialize(name,p,g,l)
|
89
|
+
super(name,p,g,l)
|
90
|
+
@categoria="Carnes y Derivados"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Esta clase permite representar un alimento en la categoria pescados
|
95
|
+
class Pescados < Alimento
|
96
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
97
|
+
# y el nombre del alimento a través del initialize de la superclass
|
98
|
+
# y se define el nombre de la categoria
|
99
|
+
def initialize(name,p,g,l)
|
100
|
+
super(name,p,g,l)
|
101
|
+
@categoria="Pescados y Maricos"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# Esta clase permite representar un alimento que tenga alto contenido en grasas
|
106
|
+
class Grasos < Alimento
|
107
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
108
|
+
# y el nombre del alimento a través del initialize de la superclass
|
109
|
+
# y se define el nombre de la categoria
|
110
|
+
def initialize(name,p,g,l)
|
111
|
+
super(name,p,g,l)
|
112
|
+
@categoria="Alimentos Grasos"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Esta clase permite representar un alimento con alto contenido de carbohidratos
|
117
|
+
class Carbohidratos < Alimento
|
118
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
119
|
+
# y el nombre del alimento a través del initialize de la superclass
|
120
|
+
# y se define el nombre de la categoria
|
121
|
+
def initialize(name,p,g,l)
|
122
|
+
super(name,p,g,l)
|
123
|
+
@categoria="Carbohidratos"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Esta clase permite representar un alimento en la categoria de verduras
|
128
|
+
class Verduras < Alimento
|
129
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
130
|
+
# y el nombre del alimento a través del initialize de la superclass
|
131
|
+
# y se define el nombre de la categoria
|
132
|
+
def initialize(name,p,g,l)
|
133
|
+
super(name,p,g,l)
|
134
|
+
@categoria="Verduras"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Esta clase permite representar un alimento en la categoria de frutas
|
139
|
+
class Frutas < Alimento
|
140
|
+
# Se definen los valores de proteinas, glucidos y lipidos
|
141
|
+
# y el nombre del alimento a través del initialize de la superclass
|
142
|
+
# y se define el nombre de la categoria
|
143
|
+
def initialize(name,p,g,l)
|
144
|
+
super(name,p,g,l)
|
145
|
+
@categoria="Frutas"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
#Clase que permite representar una receta
|
150
|
+
class Plato
|
151
|
+
attr_reader :vegetales, :frutas, :granos, :proteinas, :aceites
|
152
|
+
# Se definen los valores de conversion en @tabla y la lista de alimentos disponibles en @listaalimentos
|
153
|
+
# junto con el nombre de la receta en @name
|
154
|
+
def initialize(name,&block)
|
155
|
+
@name=name
|
156
|
+
@vegetales=[]
|
157
|
+
@frutas=[]
|
158
|
+
@granos=[]
|
159
|
+
@proteinas=[]
|
160
|
+
@aceites=[]
|
161
|
+
@tabla={"cups" => 2, "piece" => 1, "glass" => 1.5, "grams" => 0.05 }
|
162
|
+
@listaalimentos=[ DerivadoLacteo.new("Huevo", 14.1,0,19.5),
|
163
|
+
DerivadoLacteo.new("Leche", 3.3,4.8,3.2),
|
164
|
+
DerivadoLacteo.new("Yogurt", 3.8,4.9,3.8),
|
165
|
+
Carnes.new("Cerdo", 21.5,0,6.3),
|
166
|
+
Carnes.new("ternera", 21.1,0,3.1),
|
167
|
+
Carnes.new("pollo", 20.6,0,5.6),
|
168
|
+
Pescados.new("bacalao", 17.7,0,0.4),
|
169
|
+
Pescados.new("atun", 21.5,0,15.5),
|
170
|
+
Pescados.new("salmon", 19.9,0,13.6),
|
171
|
+
Grasos.new("aceite de oliva", 0,0.2,99.6),
|
172
|
+
Grasos.new("mantequilla", 0.7,0,83.2),
|
173
|
+
Grasos.new("chocolate", 5.3,47.0,30.0),
|
174
|
+
Carbohidratos.new("azucar", 0,99.8,0),
|
175
|
+
Carbohidratos.new("arroz", 6.8,77.7,0.6),
|
176
|
+
Carbohidratos.new("lentejas", 23.5,52.0,1.4),
|
177
|
+
Carbohidratos.new("papas", 2,15.4,0.1),
|
178
|
+
Verduras.new("tomate", 1,3.5,0.2),
|
179
|
+
Verduras.new("cebolla", 1.3,5.8,0.3),
|
180
|
+
Verduras.new("calabaza", 1.1,4.8,0.1),
|
181
|
+
Frutas.new("manzana", 0.3,12.4,0.4),
|
182
|
+
Frutas.new("platano", 1.2,21.4,0.2),
|
183
|
+
Frutas.new("pera", 0.5,12.7,0.3)]
|
184
|
+
|
185
|
+
if block_given?
|
186
|
+
instance_eval(&block)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
#Metodo que inserta un vegetal al plato
|
191
|
+
def vegetal(name,options = {})
|
192
|
+
vegetal=@listaalimentos.select do |alimento|
|
193
|
+
alimento.nombre.downcase == name.downcase
|
194
|
+
end
|
195
|
+
|
196
|
+
if options[:porcion]
|
197
|
+
info=options[:porcion].split(/\W+/)
|
198
|
+
amount=info[0].to_i*@tabla[info[1]]
|
199
|
+
vegetal << amount;
|
200
|
+
end
|
201
|
+
|
202
|
+
@vegetales<<vegetal
|
203
|
+
end
|
204
|
+
|
205
|
+
#Metodo que inserta una fruta al plato
|
206
|
+
def fruta(name,options = {})
|
207
|
+
fruta=@listaalimentos.select do |alimento|
|
208
|
+
alimento.nombre.downcase == name.downcase
|
209
|
+
end
|
210
|
+
|
211
|
+
if options[:porcion]
|
212
|
+
info=options[:porcion].split(/\W+/)
|
213
|
+
amount=info[0].to_i*@tabla[info[1]]
|
214
|
+
fruta << amount;
|
215
|
+
end
|
216
|
+
|
217
|
+
@frutas << fruta
|
218
|
+
end
|
219
|
+
|
220
|
+
#Metodo que inserta un cereal al plato
|
221
|
+
def cereal(name,options = {})
|
222
|
+
cereal=@listaalimentos.select do |alimento|
|
223
|
+
alimento.nombre.downcase == name.downcase
|
224
|
+
end
|
225
|
+
|
226
|
+
if options[:porcion]
|
227
|
+
info=options[:porcion].split(/\W+/)
|
228
|
+
amount=info[0].to_i*@tabla[info[1]]
|
229
|
+
cereal << amount;
|
230
|
+
end
|
231
|
+
|
232
|
+
@granos << cereal
|
233
|
+
end
|
234
|
+
|
235
|
+
#Metodo que inserta proteinas al plato
|
236
|
+
def proteina(name,options = {})
|
237
|
+
proteinas=@listaalimentos.select do |alimento|
|
238
|
+
alimento.nombre.downcase == name.downcase
|
239
|
+
end
|
240
|
+
|
241
|
+
if options[:porcion]
|
242
|
+
info=options[:porcion].split(/\W+/)
|
243
|
+
amount=info[0].to_i*@tabla[info[1]]
|
244
|
+
proteinas << amount;
|
245
|
+
end
|
246
|
+
|
247
|
+
@proteinas << proteinas
|
248
|
+
end
|
249
|
+
|
250
|
+
#Metodo que inserta aceite al plato
|
251
|
+
def aceite(name,options = {})
|
252
|
+
aceite=@listaalimentos.select do |alimento|
|
253
|
+
alimento.nombre.downcase == name.downcase
|
254
|
+
end
|
255
|
+
|
256
|
+
if options[:porcion]
|
257
|
+
info=options[:porcion].split(/\W+/)
|
258
|
+
amount=info[0].to_i*@tabla[info[1]]
|
259
|
+
aceite << amount;
|
260
|
+
end
|
261
|
+
|
262
|
+
@aceites << aceite
|
263
|
+
end
|
264
|
+
|
265
|
+
#Metodo que transforma el objeto plato en una tabla representada en un string
|
266
|
+
def to_s
|
267
|
+
output = @name
|
268
|
+
output << "\n#{'='*@name.size}\n\n"
|
269
|
+
output << "Composicion Nutricional:\n\n"
|
270
|
+
output << "%-20s %12s %12s %12s %20s\n" % ["NOMBRE","GLUCIDOS","PROTEINAS","LIPIDOS","VALOR ENERGETICO"]
|
271
|
+
@vegetales.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] }
|
272
|
+
@granos.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] }
|
273
|
+
@frutas.each{ |i| output <<"%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] }
|
274
|
+
@proteinas.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] }
|
275
|
+
@aceites.each{ |i| output << "%-20s %12.1f %12.1f %12.1f %20.1f\n" % [i[0].nombre,i[0].glucidos,i[0].proteinas,i[0].lipidos,i[0].energeticValue*i[1]] }
|
276
|
+
total=0
|
277
|
+
@vegetales.each{ |i| total += i[0].energeticValue*i[1] }
|
278
|
+
@granos.each{ |i| total += i[0].energeticValue*i[1] }
|
279
|
+
@frutas.each{ |i| total += i[0].energeticValue*i[1] }
|
280
|
+
@proteinas.each{ |i| total += i[0].energeticValue*i[1] }
|
281
|
+
@aceites.each{ |i| total += i[0].energeticValue*i[1] }
|
282
|
+
output << "\nTOTAL: %73.2f" % [total]
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
end
|
287
|
+
|
288
|
+
# Este módulo se ha creado para describir
|
289
|
+
# la clase Lista
|
290
|
+
# Author:: Alejandro González Alonso (mailto:alu0100997910@ull.edu.es)
|
291
|
+
# Copyright:: Creative Commons
|
292
|
+
# License:: Distributes under the same terms as Ruby
|
293
|
+
|
294
|
+
module Lista
|
295
|
+
# Esta clase permite representar una lista doblemente enlazadas
|
296
|
+
# Se han incluido el mixin Enumerable.
|
297
|
+
class Lista
|
298
|
+
include Enumerable
|
299
|
+
Node = Struct.new(:prev, :value, :next)
|
300
|
+
|
301
|
+
# Inicializa la clase con un valor
|
302
|
+
def initialize(val)
|
303
|
+
if val.instance_of?Array
|
304
|
+
val.each_with_index do |value,i|
|
305
|
+
if i==0
|
306
|
+
first=Node.new(nil,value,nil)
|
307
|
+
@head=first
|
308
|
+
@tail=first
|
309
|
+
else
|
310
|
+
aux=Node.new(@tail, value, nil)
|
311
|
+
@tail.next=aux
|
312
|
+
@tail=aux
|
313
|
+
end
|
314
|
+
end
|
315
|
+
else
|
316
|
+
first=Node.new(nil,val,nil)
|
317
|
+
@head=first
|
318
|
+
@tail=first
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
# Añade los valores a la lista desde el final
|
323
|
+
def push(val)
|
324
|
+
if val.instance_of?Array
|
325
|
+
val.each do |i|
|
326
|
+
aux=Node.new(@tail, i, nil)
|
327
|
+
@tail.next=aux
|
328
|
+
@tail=aux
|
329
|
+
end
|
330
|
+
else
|
331
|
+
aux=Node.new(@tail, val, nil)
|
332
|
+
@tail.next=aux
|
333
|
+
@tail=aux
|
334
|
+
end
|
335
|
+
@tail.value
|
336
|
+
end
|
337
|
+
|
338
|
+
# Elimina el primer elemento de la lista
|
339
|
+
def pop_front
|
340
|
+
aux=@head.value
|
341
|
+
@head=@head.next
|
342
|
+
@head.prev.next=nil
|
343
|
+
@head.prev=nil
|
344
|
+
aux
|
345
|
+
end
|
346
|
+
|
347
|
+
# Elimina el ultimo elemento de la lista
|
348
|
+
def pop_back
|
349
|
+
aux=@tail.value
|
350
|
+
@tail=@tail.prev
|
351
|
+
@tail.next.prev=nil
|
352
|
+
@tail.next=nil
|
353
|
+
aux
|
354
|
+
end
|
355
|
+
|
356
|
+
# Se incluye el metodo del mixin Enumerable
|
357
|
+
# Se define como una iteración sobre los elementos de la lista
|
358
|
+
def each
|
359
|
+
current=@head
|
360
|
+
while current!=nil
|
361
|
+
yield current.value
|
362
|
+
current=current.next
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
#Metodo de ordenacion con bucles for
|
367
|
+
def sortWFor
|
368
|
+
arr=[]
|
369
|
+
current=@head
|
370
|
+
while (current!=nil)
|
371
|
+
arr << current.value
|
372
|
+
current=current.next
|
373
|
+
end
|
374
|
+
|
375
|
+
for i in 1..arr.size-1
|
376
|
+
for j in 0..arr.size-i-1
|
377
|
+
if arr[j+1]<arr[j]
|
378
|
+
aux=arr[j+1]
|
379
|
+
arr[j+1]=arr[j]
|
380
|
+
arr[j]=aux
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
arr
|
385
|
+
end
|
386
|
+
|
387
|
+
#Metodo de ordenacion con metodos each
|
388
|
+
def sortWEach
|
389
|
+
arr=[]
|
390
|
+
current=@head
|
391
|
+
while (current!=nil)
|
392
|
+
arr << current.value
|
393
|
+
current=current.next
|
394
|
+
end
|
395
|
+
|
396
|
+
arr.each.with_index(1) do |val,i|
|
397
|
+
arr.each_with_index do |val2,j|
|
398
|
+
if (j<arr.size-i)
|
399
|
+
if arr[j+1]<arr[j]
|
400
|
+
aux=arr[j+1]
|
401
|
+
arr[j+1]=arr[j]
|
402
|
+
arr[j]=aux
|
403
|
+
end
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
# Formatea la Lista a una cadena de caracteres
|
410
|
+
def to_s
|
411
|
+
current=@head
|
412
|
+
sout="["
|
413
|
+
while current!=nil
|
414
|
+
if current.next==nil
|
415
|
+
sout+=current.value.to_s
|
416
|
+
else
|
417
|
+
sout+=current.value.to_s + ","
|
418
|
+
end
|
419
|
+
current=current.next
|
420
|
+
end
|
421
|
+
sout+="]"
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|