alimento-alu0100912005 0.1.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 +2 -0
- data/.gitignore +12 -0
- data/.travis.yml +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +81 -0
- data/Rakefile +6 -0
- data/alimento.gemspec +43 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc/Aibc.html +434 -0
- data/doc/Alimento.html +128 -0
- data/doc/Food.html +1063 -0
- data/doc/ListaDoblementeEnlazada.html +1308 -0
- data/doc/Node.html +409 -0
- data/doc/Piramide.html +407 -0
- data/doc/_index.html +164 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +499 -0
- data/doc/file.README.html +146 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +146 -0
- data/doc/js/app.js +248 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +307 -0
- data/doc/top-level-namespace.html +112 -0
- data/docs/Aibc.html +434 -0
- data/docs/Alimento.html +128 -0
- data/docs/Food.html +1063 -0
- data/docs/ListaDoblementeEnlazada.html +1308 -0
- data/docs/Node.html +409 -0
- data/docs/Piramide.html +407 -0
- data/docs/_index.html +164 -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 +146 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +146 -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/alimento.rb +8 -0
- data/lib/alimento/alimento.rb +152 -0
- data/lib/alimento/lista.rb +176 -0
- data/lib/alimento/plato.rb +233 -0
- data/lib/alimento/version.rb +4 -0
- metadata +213 -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="Aibc.html" title="Aibc (class)">Aibc</a></span>, <span class='object_link'><a href="Food.html" title="Food (class)">Food</a></span>, <span class='object_link'><a href="ListaDoblementeEnlazada.html" title="ListaDoblementeEnlazada (class)">ListaDoblementeEnlazada</a></span>, <span class='object_link'><a href="Node.html" title="Node (class)">Node</a></span>, <span class='object_link'><a href="Piramide.html" title="Piramide (class)">Piramide</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 Tue Nov 28 15:32:54 2017 by
|
106
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
|
+
0.9.9 (ruby-2.1.5).
|
108
|
+
</div>
|
109
|
+
|
110
|
+
</div>
|
111
|
+
</body>
|
112
|
+
</html>
|
data/lib/alimento.rb
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
# require "alimento/alimento"
|
2
|
+
|
3
|
+
# @author Nicolangelo Famiglietti
|
4
|
+
# @note Clase Food (Alimento)
|
5
|
+
class Food
|
6
|
+
# @note Se tiene acceso de lectura y escritura a todos los atributos
|
7
|
+
attr_accessor :nombre, :proteinas, :glucidos, :grasas, :n_grupo, :valores, :glucosa
|
8
|
+
# @note Clase Comparable
|
9
|
+
include Comparable
|
10
|
+
# @note Inicializador
|
11
|
+
# == Returns:
|
12
|
+
# Inicializa nombre, proteinas, glucidos y grasas
|
13
|
+
def initialize(nombre, proteinas, glucidos, grasas)
|
14
|
+
@nombre, @proteinas, @glucidos, @grasas, @valores = nombre, proteinas, glucidos, grasas
|
15
|
+
end
|
16
|
+
# @note Método to_s
|
17
|
+
# == Returns:
|
18
|
+
#Devuelve los datos del alimento formateado
|
19
|
+
def to_s
|
20
|
+
s="#{@nombre}: #{@proteinas} · #{@glucidos} · #{@grasas}"
|
21
|
+
return s
|
22
|
+
end
|
23
|
+
# @note Método get_ve
|
24
|
+
# == Returns:
|
25
|
+
#Devuelve el valor en calorias del alimento
|
26
|
+
def get_ve
|
27
|
+
sum = (@proteinas * 4) + (@glucidos * 4) + (@grasas * 9)
|
28
|
+
# aux = "#{sum}" + " Kcal"
|
29
|
+
return sum
|
30
|
+
end
|
31
|
+
|
32
|
+
# @note Metodo comparable de la clase Food
|
33
|
+
# == Returns:
|
34
|
+
# 0 Si es igual
|
35
|
+
# 1 Si es mayor
|
36
|
+
# -1 Si es menor
|
37
|
+
def <=>(other)
|
38
|
+
if @proteinas == other.proteinas
|
39
|
+
if @glucidos == other.glucidos
|
40
|
+
if @grasas == other.grasas
|
41
|
+
return 0
|
42
|
+
elsif
|
43
|
+
grasas > other.grasas
|
44
|
+
return 1
|
45
|
+
else
|
46
|
+
return -1
|
47
|
+
end
|
48
|
+
elsif
|
49
|
+
glucidos > other.glucidos
|
50
|
+
return 1
|
51
|
+
else
|
52
|
+
return -1
|
53
|
+
end
|
54
|
+
elsif
|
55
|
+
proteinas > other.proteinas
|
56
|
+
return 1
|
57
|
+
else
|
58
|
+
return -1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# @note Clase Piramide que hereda de Food
|
64
|
+
class Piramide < Food
|
65
|
+
# @note Inicializador de la clase heredada
|
66
|
+
# == Returns:
|
67
|
+
# Inicializa nombre, proteinas, glucidos, grasas y nombre de grupo
|
68
|
+
def initialize(nombre, proteinas, glucidos, grasas, n_grupo)
|
69
|
+
super(nombre, proteinas, glucidos, grasas)
|
70
|
+
@n_grupo = n_grupo
|
71
|
+
end
|
72
|
+
# @note Método to_s
|
73
|
+
# == Returns:
|
74
|
+
#Devuelve el nombre del grupo al que pertenece el alimento
|
75
|
+
def to_s
|
76
|
+
@nombre
|
77
|
+
end
|
78
|
+
# @note Método devolver_nombre_grupo
|
79
|
+
# == Returns:
|
80
|
+
#Devuelve el nombre del grupo al que pertenece el alimento
|
81
|
+
def devolver_nombre_grupo
|
82
|
+
@n_grupo
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# @note Clase Aibc heredada de Food para el calculo del aibc del alimento
|
87
|
+
class Aibc < Food
|
88
|
+
# @note Inicializador de la clase heredada
|
89
|
+
# == Returns:
|
90
|
+
# Inicializa nombre, proteinas, glucidos, grasas y valores
|
91
|
+
def initialize(nombre, proteinas, glucidos, grasas, valores, glucosa)
|
92
|
+
super(nombre, proteinas, glucidos, grasas)
|
93
|
+
@g = valores
|
94
|
+
@glu = glucosa
|
95
|
+
end
|
96
|
+
# @note Metodo AIBC para el calculo del indice glucémico
|
97
|
+
# == Returns:
|
98
|
+
# Valor del indice glucémico
|
99
|
+
def aibc
|
100
|
+
r = []
|
101
|
+
(0..1).collect{
|
102
|
+
|i|
|
103
|
+
s = []
|
104
|
+
(1..24).collect{
|
105
|
+
|index|
|
106
|
+
if @g[i][index] < @g[i][0]
|
107
|
+
s << 0.0
|
108
|
+
else
|
109
|
+
s << (((@g[i][index] - @g[i][0]) + (@g[i][index-1] - @g[i][0]))/2)*5
|
110
|
+
end
|
111
|
+
}
|
112
|
+
r << s
|
113
|
+
}
|
114
|
+
|
115
|
+
aibc_alimento = []
|
116
|
+
(0..1).collect{ |j|
|
117
|
+
s=0
|
118
|
+
(0..23).collect{
|
119
|
+
|k|
|
120
|
+
s = s + r[j][k]
|
121
|
+
}
|
122
|
+
aibc_alimento << s
|
123
|
+
}
|
124
|
+
|
125
|
+
r1 = []
|
126
|
+
(0..1).collect{
|
127
|
+
|i1|
|
128
|
+
s1 = []
|
129
|
+
(1..24).collect{
|
130
|
+
|index1|
|
131
|
+
if @glu[i1][index1] < @glu[i1][0]
|
132
|
+
s1 << 0.0
|
133
|
+
else
|
134
|
+
s1 << (((@glu[i1][index1] - @glu[i1][0]) + (@glu[i1][index1-1] - @glu[i1][0]))/2)*5
|
135
|
+
end
|
136
|
+
}
|
137
|
+
r1 << s1
|
138
|
+
}
|
139
|
+
aibc_glucosa = []
|
140
|
+
(0..1).collect{
|
141
|
+
|j1|
|
142
|
+
s1=0
|
143
|
+
(0..23).collect{
|
144
|
+
|k1|
|
145
|
+
s1 = s1 + r1[j1][k1]
|
146
|
+
}
|
147
|
+
aibc_glucosa << s1
|
148
|
+
}
|
149
|
+
|
150
|
+
ig_alimento = (((aibc_alimento[0] /aibc_glucosa[0])*100) + (((aibc_alimento[1] /aibc_glucosa[1]))*100))/2
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
# require "alimento/version"
|
2
|
+
require_relative "alimento"
|
3
|
+
|
4
|
+
# create a Struct with :value, :next and :prev
|
5
|
+
Node = Struct.new(:value, :next, :prev)
|
6
|
+
# @author Nicolangelo Famiglietti
|
7
|
+
# @note Clase ListaDoblementeEnlazada - Lista doblemente enlazada
|
8
|
+
class ListaDoblementeEnlazada
|
9
|
+
attr_reader :head, :tail
|
10
|
+
include Enumerable
|
11
|
+
# @note Inicializador
|
12
|
+
# == Returns:
|
13
|
+
#Inicilizacion de la cola y la cabeza
|
14
|
+
def initialize
|
15
|
+
@head = @tail = nil
|
16
|
+
end
|
17
|
+
# @note Método to_s
|
18
|
+
# == Returns:
|
19
|
+
#Devuelve la lista de alimentos formateada
|
20
|
+
def to_s
|
21
|
+
aux = @head
|
22
|
+
s= aux.value.n_grupo
|
23
|
+
s+="\n"
|
24
|
+
s+= "\t\t\tProteinas Glucidos Lipidos\n"
|
25
|
+
while(aux != nil)
|
26
|
+
s+="\t#{aux.value.nombre} \t#{aux.value.proteinas} \t #{aux.value.glucidos} #{aux.value.grasas}\n"
|
27
|
+
aux= aux[:next]
|
28
|
+
end
|
29
|
+
s
|
30
|
+
end
|
31
|
+
# @note Método size
|
32
|
+
# == Returns:
|
33
|
+
#Devuelve el tamaño de la lista
|
34
|
+
def size
|
35
|
+
count = 0
|
36
|
+
if @head[:value] != nil then
|
37
|
+
count=1
|
38
|
+
end
|
39
|
+
aux= @head
|
40
|
+
until aux[:next] == nil do
|
41
|
+
count+=1
|
42
|
+
aux=aux[:next]
|
43
|
+
end
|
44
|
+
count
|
45
|
+
end
|
46
|
+
# @note Método empty
|
47
|
+
# == Returns:
|
48
|
+
#true si esta vacio
|
49
|
+
#false si contiene algo
|
50
|
+
def empty
|
51
|
+
if(@head == nil)
|
52
|
+
true
|
53
|
+
elsif
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# @note Método insert
|
59
|
+
# == Returns:
|
60
|
+
#Inserta un elemento en la lista
|
61
|
+
#Devuelve true si se realizó correctamente
|
62
|
+
def insert(value)
|
63
|
+
node = Node.new(value, nil)
|
64
|
+
if(empty)
|
65
|
+
@head = node
|
66
|
+
@tail = node
|
67
|
+
elsif
|
68
|
+
@tail.next = node
|
69
|
+
@tail = node
|
70
|
+
end
|
71
|
+
true
|
72
|
+
end
|
73
|
+
# @note Método extract_head
|
74
|
+
# == Returns:
|
75
|
+
#El elemento a extraer por la cabeza
|
76
|
+
def extract_head
|
77
|
+
nodo = @head
|
78
|
+
if nodo != nil
|
79
|
+
if nodo.next != nil
|
80
|
+
@head = nodo.next
|
81
|
+
else
|
82
|
+
@head = nil
|
83
|
+
@tail = nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
nodo
|
87
|
+
end
|
88
|
+
# @note Método extract_tail
|
89
|
+
# == Returns:
|
90
|
+
#El elemento a extraer por la cola
|
91
|
+
def extract_tail
|
92
|
+
aux = nil
|
93
|
+
if @tail[:value]==nil
|
94
|
+
aux=nil
|
95
|
+
else
|
96
|
+
aux = @tail[:value]
|
97
|
+
@tail = @tail[:prev]
|
98
|
+
@tail = nil
|
99
|
+
end
|
100
|
+
if @tail==nil
|
101
|
+
@tail = Node.new
|
102
|
+
@head = @tail
|
103
|
+
end
|
104
|
+
aux
|
105
|
+
end
|
106
|
+
# @note Método Enumerable
|
107
|
+
# == Returns:
|
108
|
+
# Enumerable
|
109
|
+
# Metodo de acceso a acada elemento
|
110
|
+
def each
|
111
|
+
aux = @head
|
112
|
+
while(aux != nil)
|
113
|
+
yield aux[:value]
|
114
|
+
aux= aux[:next]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# @note Metodo comparable de la clase Food
|
119
|
+
# == Returns:
|
120
|
+
# 0 Si es igual
|
121
|
+
# 1 Si es mayor
|
122
|
+
# -1 Si es menor
|
123
|
+
def <=>(other)
|
124
|
+
if @ve == other.ve
|
125
|
+
return 0
|
126
|
+
elsif
|
127
|
+
ve > other.ve
|
128
|
+
return 1
|
129
|
+
else
|
130
|
+
return -1
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def sortFor(lista)
|
135
|
+
numbers=[]
|
136
|
+
a=0
|
137
|
+
lista.each{|x|
|
138
|
+
numbers[a] = x
|
139
|
+
a=a+1
|
140
|
+
}
|
141
|
+
for i in 0..numbers.size-1 do
|
142
|
+
for j in 0..numbers.size-1 do
|
143
|
+
if(numbers[i].get_ve < numbers[j].get_ve)
|
144
|
+
aux = numbers[j]
|
145
|
+
numbers[j] = numbers[i]
|
146
|
+
numbers[i] = aux
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
lista = []
|
151
|
+
a=0
|
152
|
+
numbers.each{|x|
|
153
|
+
lista[a] = x.get_ve
|
154
|
+
a=a+1
|
155
|
+
}
|
156
|
+
lista
|
157
|
+
end
|
158
|
+
|
159
|
+
def sortEach(lista)
|
160
|
+
numbers = []
|
161
|
+
i=0
|
162
|
+
numbers[i] = lista.extract_head.value
|
163
|
+
lista.each {|x|
|
164
|
+
if numbers[i] > x
|
165
|
+
aux = numbers[i]
|
166
|
+
numbers[i] = x
|
167
|
+
i=i+1
|
168
|
+
numbers[i] = aux
|
169
|
+
else
|
170
|
+
i=i+1
|
171
|
+
numbers[i] = x
|
172
|
+
end
|
173
|
+
}
|
174
|
+
numbers
|
175
|
+
end
|
176
|
+
end
|