comiditaULL 0.1.1
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 +12 -0
- data/.rake_tasks~ +7 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Alimento.gemspec +47 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimento.html +151 -0
- data/docs/Comida.html +745 -0
- data/docs/GruposAlimento.html +389 -0
- data/docs/List.html +915 -0
- data/docs/Node.html +410 -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 +130 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +130 -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 +243 -0
- data/docs/top-level-namespace.html +112 -0
- data/lib/Alimento.rb +18 -0
- data/lib/Alimento/Comida.rb +40 -0
- data/lib/Alimento/GruposAlimento.rb +18 -0
- data/lib/Alimento/IndiceGlucemico.rb +34 -0
- data/lib/Alimento/List.rb +230 -0
- data/lib/Alimento/Plato.rb +110 -0
- data/lib/Alimento/version.rb +4 -0
- metadata +1836 -0
@@ -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="Alimento.html" title="Alimento (module)">Alimento</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Comida.html" title="Comida (class)">Comida</a></span>, <span class='object_link'><a href="GruposAlimento.html" title="GruposAlimento (class)">GruposAlimento</a></span>, <span class='object_link'><a href="List.html" title="List (class)">List</a></span>, <span class='object_link'><a href="Node.html" title="Node (class)">Node</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 10:38:30 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.1).
|
108
|
+
</div>
|
109
|
+
|
110
|
+
</div>
|
111
|
+
</body>
|
112
|
+
</html>
|
data/lib/Alimento.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "Alimento/version"
|
3
|
+
require "Alimento/Comida"
|
4
|
+
require "Alimento/List"
|
5
|
+
require "Alimento/GruposAlimento"
|
6
|
+
require "Alimento/IndiceGlucemico"
|
7
|
+
require "Alimento/Plato"
|
8
|
+
|
9
|
+
# Este módulo se ha creado para describir distintas metodologías de un alimento
|
10
|
+
# haciendo uso de Ruby como lenguaje de programación
|
11
|
+
#
|
12
|
+
# Author:: Abel Delgadon (mailto:alu0100792218@ull.edu.es)
|
13
|
+
# Copyright:: Cretive Commons
|
14
|
+
# License:: Distributes under the same terms as Ruby
|
15
|
+
|
16
|
+
module Alimento
|
17
|
+
# Your code goes here
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Esta clase permite representar un alimento con sus valores energeticos y un calculo del mismo
|
2
|
+
# Contiene metodos para el manejo de la misma facilmente.
|
3
|
+
# Se ha incluido el mixin Comparable.
|
4
|
+
class Comida
|
5
|
+
|
6
|
+
# Permite acceder a los atributos de la clase en forma de lectura.
|
7
|
+
# Actuan como "getters".
|
8
|
+
attr_reader :comida, :proteina, :glucidos, :lipidos
|
9
|
+
|
10
|
+
include Comparable
|
11
|
+
|
12
|
+
# Se asignan los valores del alimento a sus atributos
|
13
|
+
def initialize(nombre, proteinas, glucidos, lipidos)
|
14
|
+
|
15
|
+
@comida = nombre
|
16
|
+
@proteina = proteinas
|
17
|
+
@glucidos = glucidos
|
18
|
+
@lipidos = lipidos
|
19
|
+
end
|
20
|
+
|
21
|
+
# Permite formatear la salida por pantalla.
|
22
|
+
def to_s
|
23
|
+
"#{comida}, #{proteina}, #{glucidos}, #{lipidos}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# Calcula el valor energético del alimento
|
27
|
+
def valorEnergetico
|
28
|
+
aux=0
|
29
|
+
aux = ( (@proteina*4) + (@lipidos*9) + (@glucidos*4) )
|
30
|
+
end
|
31
|
+
|
32
|
+
# Se incluye el metodo del mixin Comparable
|
33
|
+
# Se define como una comparacion de dos objetos a través de su valor energético.
|
34
|
+
def <=>(other)
|
35
|
+
if(other.is_a? Comida)
|
36
|
+
valorEnergetico <=> other.valorEnergetico
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Esta clase permite representar un grupo de alimentos que se relacionan.
|
2
|
+
# Hereda de la clase comida.
|
3
|
+
class GruposAlimento < Comida
|
4
|
+
|
5
|
+
# Permite acceder a los atributos de la clase en forma de lectura.
|
6
|
+
attr_reader :grupo
|
7
|
+
|
8
|
+
# Crea el grupo de alimentos y llama a su clase padre.
|
9
|
+
def initialize (group, nombre, proteinas, glucidos, lipidos)
|
10
|
+
super(nombre, proteinas, glucidos, lipidos)
|
11
|
+
@grupo = group
|
12
|
+
end
|
13
|
+
|
14
|
+
# Permite formatear la salida por pantalla.
|
15
|
+
def to_s
|
16
|
+
"#{grupo}" + ", " + super.to_s
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Esta clase permite calcular el indice glucémico de un alimento.
|
2
|
+
# Hereda de la clase comida.
|
3
|
+
class IndiceGlucemico < Comida
|
4
|
+
|
5
|
+
# Permite acceder a los atributos de la clase en forma de lectura.
|
6
|
+
attr_reader :dat
|
7
|
+
|
8
|
+
# Crea el vector con el contenido y llama a su clase padre.
|
9
|
+
def initialize (nombre, proteinas, glucidos, lipidos, vector)
|
10
|
+
super(nombre, proteinas, glucidos, lipidos)
|
11
|
+
@dat = vector
|
12
|
+
end
|
13
|
+
|
14
|
+
# Permite formatear la salida por pantalla.
|
15
|
+
def to_s
|
16
|
+
super.to_s + ", " + "#{dat}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def aibc
|
20
|
+
@dat.collect do |ind|
|
21
|
+
ind.zip(1..ind.size).collect do |val, index|
|
22
|
+
if ((index == ind.size) || (ind[index] < ind[0]))
|
23
|
+
0.0
|
24
|
+
else
|
25
|
+
(((ind[index] - ind[0]) + (ind[index-1] - ind[0] )) / 2)*5
|
26
|
+
end
|
27
|
+
end.reduce('+')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def indiceg(other)
|
32
|
+
(((self.aibc).zip(other.aibc)).collect {|v1 , v2| ((v1 / v2) * 100)}.reduce('+')) / ((self.aibc).size)
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
#Estructura que define los nodos de la lista.
|
2
|
+
#Contiene un campo para el valor y dos apuntadores a
|
3
|
+
#los nodos siguiente y anterior.
|
4
|
+
Node = Struct.new(:value, :next, :prev)
|
5
|
+
|
6
|
+
# Esta clase permite representar una lista doblemente enlazada con un head y un tail.
|
7
|
+
# Contiene metodos para el manejo de la misma facilmente.
|
8
|
+
# Se ha incluido el mixin Enumerable.
|
9
|
+
class List
|
10
|
+
|
11
|
+
# Permite acceder a los atributos de la clase en forma de lectura.
|
12
|
+
attr_reader :head, :tail
|
13
|
+
|
14
|
+
include Enumerable
|
15
|
+
|
16
|
+
# Se asignan los valores de la cabeza y cola de la lista, inicialmente no hay nada.
|
17
|
+
def initialize
|
18
|
+
@head = nil
|
19
|
+
@tail = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
# Inserta un valor por la cabeza a la lista.
|
23
|
+
def insert_head (value)
|
24
|
+
newNode = Node.new(value, nil, nil)
|
25
|
+
|
26
|
+
if (empty())
|
27
|
+
@head = newNode
|
28
|
+
@tail = newNode
|
29
|
+
else
|
30
|
+
@head.next = newNode
|
31
|
+
newNode.prev = @head
|
32
|
+
@head = newNode
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Inserta un valor por la cola a la lista.
|
37
|
+
def insert_tail (value)
|
38
|
+
newNode = Node.new(value, nil, nil)
|
39
|
+
|
40
|
+
if (empty)
|
41
|
+
@head = newNode
|
42
|
+
@tail = newNode
|
43
|
+
else
|
44
|
+
@tail.prev = newNode
|
45
|
+
newNode.next = @tail
|
46
|
+
@tail = newNode
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Comprueba si la lista esta vacia y devuelve un boolean.
|
51
|
+
def empty
|
52
|
+
if (@head == nil)
|
53
|
+
true
|
54
|
+
else
|
55
|
+
false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Permite insertar varios valores al mismo tiempo con una sola llamada.
|
60
|
+
def insert_values(vec)
|
61
|
+
vec.each do |i|
|
62
|
+
insert_head(i)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Extrae el elemento que se encuentre en la cabeza de la lista.
|
67
|
+
def extract_head
|
68
|
+
aux = @head
|
69
|
+
if (!empty())
|
70
|
+
@head = @head.prev
|
71
|
+
end
|
72
|
+
return aux
|
73
|
+
end
|
74
|
+
|
75
|
+
# Extrae el elemento que se encuentre en la cola de la lista.
|
76
|
+
def extract_tail
|
77
|
+
aux = @tail
|
78
|
+
if (!empty())
|
79
|
+
@tail = @tail.next
|
80
|
+
end
|
81
|
+
return aux
|
82
|
+
end
|
83
|
+
|
84
|
+
# Se incluye el metodo del mixin Enumerable
|
85
|
+
# Se define como una iteración sobre los nodos de la lista.
|
86
|
+
def each
|
87
|
+
nodoActual = @tail
|
88
|
+
while nodoActual != nil
|
89
|
+
yield nodoActual.value
|
90
|
+
nodoActual = nodoActual.next
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def bucleFor!
|
95
|
+
nodoActual = @tail
|
96
|
+
nodoSiguiente = nodoActual.next
|
97
|
+
nodoFinal = @head
|
98
|
+
while nodoFinal != @tail
|
99
|
+
while nodoSiguiente != nil
|
100
|
+
if (nodoActual.value > nodoSiguiente.value)
|
101
|
+
swap(nodoActual, nodoSiguiente, nodoFinal)
|
102
|
+
end
|
103
|
+
nodoActual = nodoSiguiente
|
104
|
+
nodoSiguiente = nodoSiguiente.next
|
105
|
+
end
|
106
|
+
nodoActual = @tail
|
107
|
+
nodoSiguiente = nodoActual.next
|
108
|
+
nodoFinal = nodoFinal.prev
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def swap (nodoActual, nodoSiguiente, nodoFinal)
|
113
|
+
|
114
|
+
checkerTail = false
|
115
|
+
checkerHead = false
|
116
|
+
|
117
|
+
if (nodoActual == @tail)
|
118
|
+
checkerTail = true
|
119
|
+
end
|
120
|
+
|
121
|
+
if (nodoSiguiente == @head)
|
122
|
+
checkerHead = true
|
123
|
+
end
|
124
|
+
|
125
|
+
nodoTmpIzq = nodoActual.prev
|
126
|
+
nodoTmpDch = nodoSiguiente.next
|
127
|
+
|
128
|
+
nodoActual = nodoSiguiente
|
129
|
+
nodoSiguiente = nodoSiguiente.prev
|
130
|
+
|
131
|
+
nodoActual.next = nodoSiguiente
|
132
|
+
nodoSiguiente.prev = nodoActual
|
133
|
+
|
134
|
+
if(nodoTmpIzq != nil)
|
135
|
+
nodoTmpIzq.next = nodoActual
|
136
|
+
nodoActual.prev = nodoTmpIzq
|
137
|
+
else
|
138
|
+
nodoActual.prev = nil
|
139
|
+
end
|
140
|
+
|
141
|
+
if(nodoTmpDch != nil)
|
142
|
+
nodoTmpDch.prev = nodoSiguiente
|
143
|
+
nodoSiguiente.next = nodoTmpDch
|
144
|
+
else
|
145
|
+
nodoSiguiente.next = nil
|
146
|
+
end
|
147
|
+
|
148
|
+
if (checkerTail)
|
149
|
+
@tail = nodoActual
|
150
|
+
end
|
151
|
+
|
152
|
+
if (checkerHead)
|
153
|
+
@head = nodoSiguiente
|
154
|
+
nodoFinal = nodoSiguiente
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def bucleEach
|
159
|
+
copia = self.dup
|
160
|
+
copiaVariable = copia.dup
|
161
|
+
listafinal = List.new
|
162
|
+
|
163
|
+
copia.each do |m|
|
164
|
+
aux = copiaVariable.tail.value
|
165
|
+
copiaVariable.each do |elem|
|
166
|
+
if (aux > elem)
|
167
|
+
aux = elem
|
168
|
+
end
|
169
|
+
end
|
170
|
+
copiaVariable = extraerNodo(copiaVariable, aux)
|
171
|
+
listafinal.insert_head(aux)
|
172
|
+
end
|
173
|
+
listafinal
|
174
|
+
end
|
175
|
+
|
176
|
+
def extraerNodo(lista, valor)
|
177
|
+
nodo = lista.tail
|
178
|
+
while nodo != nil
|
179
|
+
if (nodo.value == valor)
|
180
|
+
checkTail = false
|
181
|
+
checkHead = false
|
182
|
+
nodoTmpIzq = nodo.prev
|
183
|
+
nodoTmpDch = nodo.next
|
184
|
+
|
185
|
+
if (nodo == lista.tail)
|
186
|
+
checkTail = true
|
187
|
+
end
|
188
|
+
|
189
|
+
if (nodo == lista.head)
|
190
|
+
checkHead = true
|
191
|
+
end
|
192
|
+
|
193
|
+
if(nodoTmpIzq != nil)
|
194
|
+
nodoTmpIzq.next = nodo.next
|
195
|
+
end
|
196
|
+
|
197
|
+
if(nodoTmpDch != nil)
|
198
|
+
nodoTmpDch.prev = nodo.prev
|
199
|
+
end
|
200
|
+
|
201
|
+
if (checkHead)
|
202
|
+
lista.setHead(nodo.prev)
|
203
|
+
end
|
204
|
+
|
205
|
+
if (checkTail)
|
206
|
+
lista.setTail(nodo.next)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
nodo = nodo.next
|
210
|
+
end
|
211
|
+
lista
|
212
|
+
end
|
213
|
+
|
214
|
+
def write
|
215
|
+
nodo = @tail
|
216
|
+
while nodo != nil
|
217
|
+
p nodo.value.to_s
|
218
|
+
nodo = nodo.next
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def setTail(nodo)
|
223
|
+
@tail = nodo
|
224
|
+
end
|
225
|
+
|
226
|
+
def setHead(nodo)
|
227
|
+
@head = nodo
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|