P06axz 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/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/P06.gemspec +44 -0
- data/README.md +7 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc/Alimento.html +825 -0
- data/doc/Alimento_concreto.html +396 -0
- data/doc/List.html +858 -0
- data/doc/Node.html +423 -0
- data/doc/P06.html +117 -0
- data/doc/_index.html +151 -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 +492 -0
- data/doc/file.README.html +78 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +78 -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 +243 -0
- data/doc/top-level-namespace.html +112 -0
- data/docs/Alimento.html +682 -0
- data/docs/Alimento_concreto.html +389 -0
- data/docs/List.html +858 -0
- data/docs/Node.html +423 -0
- data/docs/P06.html +117 -0
- data/docs/_index.html +151 -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 +79 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +79 -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 +227 -0
- data/docs/top-level-namespace.html +112 -0
- data/lib/P06.rb +11 -0
- data/lib/P06/alimento.rb +37 -0
- data/lib/P06/version.rb +3 -0
- data/lib/P07/alimento_concreto.rb +10 -0
- data/lib/P07/list.rb +80 -0
- data/lib/P08/alimento_concreto.rb +25 -0
- data/lib/P08/list.rb +108 -0
- data/lib/P10/modified_array.rb +29 -0
- data/lib/P11/alimento.rb +29 -0
- data/lib/P11/plato.rb +108 -0
- data/lib/P11/porciones.rb +31 -0
- metadata +233 -0
data/lib/P06.rb
ADDED
data/lib/P06/alimento.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Esta clase permite representar la información básica
|
|
2
|
+
# de un alimento dado, sus proteinas, glúcidos y lípidos
|
|
3
|
+
# además, calcula el índice calórico del mismo.
|
|
4
|
+
#
|
|
5
|
+
# Author:: Alberto González (mailto:alu0100949568@ull.edu.es)
|
|
6
|
+
# Copyright:: Cretive Commons
|
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
|
8
|
+
class Alimento
|
|
9
|
+
attr_reader :nom, :prot, :gluc, :lip, :cal_index
|
|
10
|
+
include Enumerable, Comparable
|
|
11
|
+
# Se asigna el nombre y la información nutricional del alimento
|
|
12
|
+
def initialize(nom, prot, gluc, lip, gluc_data = nil)
|
|
13
|
+
@nom = nom
|
|
14
|
+
@prot = prot
|
|
15
|
+
@gluc = gluc
|
|
16
|
+
@lip = lip
|
|
17
|
+
@gluc_data = gluc_data
|
|
18
|
+
@cal_index = (@prot.to_f*4 + @gluc.to_f*4 + @lip.to_f*9).round(2)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Muestra la información de un alimento en concreto
|
|
22
|
+
def to_s
|
|
23
|
+
#El huevo frito tiene 14.1 proteinas, 0.0 glúcidos, 19.5 lípidos
|
|
24
|
+
" #{@nom}: #{@prot} proteinas, #{@gluc} glúcidos, #{@lip} lípidos, #{@cal_index} calorías"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Se comprueba que no sea un valor negativo, en caso de serlo, se sustituye por un 0
|
|
28
|
+
def not_negative(n)
|
|
29
|
+
n < 0 ? n = 0 : n = n
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Calcula el área bajo la curva para los datos tomados en una medición de glucosa en intervalos de tiempo de 5 minutos
|
|
33
|
+
def aibc
|
|
34
|
+
@gluc_data.map{|indv| zero = indv.at(0); prev = -2; indv.map{|index| prev = prev + 1; ((index-zero) + (indv.at(not_negative(prev))-zero))*2.5}.reduce(:+).round(2)}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
data/lib/P06/version.rb
ADDED
data/lib/P07/list.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Node = Struct.new(:value, :next, :prev)
|
|
2
|
+
|
|
3
|
+
class List
|
|
4
|
+
def initialize
|
|
5
|
+
@head = @tail = nil
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def push(value)
|
|
9
|
+
##Si es un array
|
|
10
|
+
if value.is_a?(Array)
|
|
11
|
+
value.each do |val|
|
|
12
|
+
prev = @tail unless @tail.nil?
|
|
13
|
+
while prev != @head do
|
|
14
|
+
prev = prev.next
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
node = Node.new(val, nil, prev)
|
|
18
|
+
|
|
19
|
+
@tail = node if @tail.nil?
|
|
20
|
+
@head.next = node unless @head.nil?
|
|
21
|
+
|
|
22
|
+
@head = node
|
|
23
|
+
end
|
|
24
|
+
else #Si es un único valor
|
|
25
|
+
prev = @tail unless @tail.nil?
|
|
26
|
+
while prev != @head do
|
|
27
|
+
prev = prev.next
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
node = Node.new(value, nil, prev)
|
|
31
|
+
|
|
32
|
+
@tail = node if @tail.nil?
|
|
33
|
+
@head.next = node unless @head.nil?
|
|
34
|
+
|
|
35
|
+
@head = node
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def head
|
|
40
|
+
@head.value unless @head.nil?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def tail
|
|
44
|
+
@tail.value unless @tail.nil?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def remove_tail
|
|
48
|
+
@tail = @tail.next
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def remove_head
|
|
52
|
+
@head = @head.prev
|
|
53
|
+
@head.next = nil
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def to_s
|
|
57
|
+
array = "["
|
|
58
|
+
next_val = @tail unless @tail.nil?
|
|
59
|
+
while next_val != nil do
|
|
60
|
+
array = array + next_val.value.to_s + ", "
|
|
61
|
+
next_val = next_val.next
|
|
62
|
+
|
|
63
|
+
if next_val == nil #For las element
|
|
64
|
+
array = array.chomp(', ') + "]"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
"#{array}"
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def size
|
|
71
|
+
count = 0
|
|
72
|
+
next_val = @tail unless @tail.nil?
|
|
73
|
+
while next_val != nil do
|
|
74
|
+
next_val = next_val.next
|
|
75
|
+
count +=1
|
|
76
|
+
end
|
|
77
|
+
"#{count}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Representa a un grupo de alimentos, identificados por su nombre de grupo
|
|
2
|
+
# es una clase heredada de Alimento
|
|
3
|
+
#
|
|
4
|
+
# Author:: Alberto González (mailto:alu0100949568@ull.edu.es)
|
|
5
|
+
# Copyright:: Cretive Commons
|
|
6
|
+
# License:: Distributes under the same terms as Ruby
|
|
7
|
+
class Alimento_concreto < Alimento
|
|
8
|
+
# Se han incluido los mixin Comparable.
|
|
9
|
+
include Comparable
|
|
10
|
+
def initialize(group_name, food_name, prot, gluc, lip)
|
|
11
|
+
@group_name = group_name
|
|
12
|
+
super(food_name, prot, gluc, lip)
|
|
13
|
+
end
|
|
14
|
+
# Devuelve de forma formateada el nombre del grupo al que pertenecen
|
|
15
|
+
# un grupo de alimentos, además de los alimentos que lo conforman.
|
|
16
|
+
def to_s
|
|
17
|
+
"(#{@group_name} ->#{super.to_s})"
|
|
18
|
+
end
|
|
19
|
+
# Compara dos alimentos según su índice calórico
|
|
20
|
+
def <=>(other)
|
|
21
|
+
return nil unless other.instance_of? Alimento_concreto
|
|
22
|
+
@cal_index <=> other.cal_index
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
data/lib/P08/list.rb
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# Esta estructura respresenta a un nodo de nuestra futura
|
|
3
|
+
# lista. Tiene un nodo predecesor, sucesor y un valor.
|
|
4
|
+
#
|
|
5
|
+
# Author:: Alberto González (mailto:alu0100949568@ull.edu.es)
|
|
6
|
+
# Copyright:: Cretive Commons
|
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
|
8
|
+
|
|
9
|
+
Node = Struct.new(:value, :next, :prev)
|
|
10
|
+
|
|
11
|
+
# Representa una lista doblemente enlazada con una cabeza y una cola,
|
|
12
|
+
# pudiéndose insertar un array de alimentos o alimentos individuales
|
|
13
|
+
#
|
|
14
|
+
# Author:: Alberto González (mailto:alu0100949568@ull.edu.es)
|
|
15
|
+
# Copyright:: Cretive Commons
|
|
16
|
+
# License:: Distributes under the same terms as Ruby
|
|
17
|
+
class List
|
|
18
|
+
# Se ha incluido el mixin Enumerable.
|
|
19
|
+
include Enumerable
|
|
20
|
+
# Se asigna la cabeza y cola a nil (inicialmente)
|
|
21
|
+
def initialize
|
|
22
|
+
@head = @tail = nil
|
|
23
|
+
end
|
|
24
|
+
# Método para insertar valores en la lista, se pueden
|
|
25
|
+
# insertar varios valores o un único valor.
|
|
26
|
+
def push(value)
|
|
27
|
+
##Si es un array
|
|
28
|
+
if value.is_a?(Array)
|
|
29
|
+
value.each do |val|
|
|
30
|
+
prev = @tail unless @tail.nil?
|
|
31
|
+
while prev != @head do
|
|
32
|
+
prev = prev.next
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
node = Node.new(val, nil, prev)
|
|
36
|
+
|
|
37
|
+
@tail = node if @tail.nil?
|
|
38
|
+
@head.next = node unless @head.nil?
|
|
39
|
+
|
|
40
|
+
@head = node
|
|
41
|
+
end
|
|
42
|
+
else #Si es un único valor
|
|
43
|
+
prev = @tail unless @tail.nil?
|
|
44
|
+
while prev != @head do
|
|
45
|
+
prev = prev.next
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
node = Node.new(value, nil, prev)
|
|
49
|
+
|
|
50
|
+
@tail = node if @tail.nil?
|
|
51
|
+
@head.next = node unless @head.nil?
|
|
52
|
+
|
|
53
|
+
@head = node
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Devuelve la cabeza de la lista a menos que no tenga cabeza
|
|
58
|
+
def head
|
|
59
|
+
@head.value unless @head.nil?
|
|
60
|
+
end
|
|
61
|
+
# Devuelve la cola de la lista a menos que no tenga cola
|
|
62
|
+
def tail
|
|
63
|
+
@tail.value unless @tail.nil?
|
|
64
|
+
end
|
|
65
|
+
# Borra la cola de la lista a menos que no tenga cola
|
|
66
|
+
def remove_tail
|
|
67
|
+
@tail = @tail.next unless @tail.nil?
|
|
68
|
+
end
|
|
69
|
+
# Borra la cabeza de la lista
|
|
70
|
+
def remove_head
|
|
71
|
+
@head = @head.prev
|
|
72
|
+
@head.next = nil
|
|
73
|
+
end
|
|
74
|
+
# Muestra los valores que se han almacenado en la lista
|
|
75
|
+
def to_s
|
|
76
|
+
array = "["
|
|
77
|
+
next_val = @tail unless @tail.nil?
|
|
78
|
+
while next_val != nil do
|
|
79
|
+
array = array + next_val.value.to_s + ", "
|
|
80
|
+
next_val = next_val.next
|
|
81
|
+
|
|
82
|
+
if next_val == nil #For las element
|
|
83
|
+
array = array.chomp(', ') + "]"
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
"#{array}"
|
|
87
|
+
end
|
|
88
|
+
# Devuelve la cantidad de nodos que tiene nuestra lista
|
|
89
|
+
def size
|
|
90
|
+
count = 0
|
|
91
|
+
next_val = @tail unless @tail.nil?
|
|
92
|
+
while next_val != nil do
|
|
93
|
+
next_val = next_val.next
|
|
94
|
+
count +=1
|
|
95
|
+
end
|
|
96
|
+
"#{count}"
|
|
97
|
+
end
|
|
98
|
+
# Método que nos permite recorrer cada uno de los nodos de nuestra lista
|
|
99
|
+
def each
|
|
100
|
+
next_val = @tail
|
|
101
|
+
while next_val != nil do
|
|
102
|
+
yield next_val.value
|
|
103
|
+
next_val = next_val.next
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class Array
|
|
2
|
+
def bubble_sort
|
|
3
|
+
i = 0
|
|
4
|
+
j = 0
|
|
5
|
+
v_aux = self.clone
|
|
6
|
+
while j < v_aux.size-1 do
|
|
7
|
+
while i < v_aux.size-1 do
|
|
8
|
+
if v_aux[i] > v_aux[i+1]
|
|
9
|
+
aux = v_aux[i]
|
|
10
|
+
v_aux[i] = v_aux[i+1]
|
|
11
|
+
v_aux[i+1] = aux
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
i = i+1
|
|
15
|
+
end
|
|
16
|
+
j = j+1
|
|
17
|
+
i = 0
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
v_aux
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def bubble_sort_func
|
|
24
|
+
self_ = self.clone
|
|
25
|
+
aux = self.clone
|
|
26
|
+
(0..self.size-1).each{|x| min = self_.min; prev = aux[x]; aux[x] = min; self_.delete(min)}
|
|
27
|
+
aux
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/P11/alimento.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class Alimento
|
|
2
|
+
attr_reader :nom, :prot, :gluc, :lip, :cal_index
|
|
3
|
+
include Enumerable, Comparable
|
|
4
|
+
# Se asigna el nombre y la información nutricional del alimento
|
|
5
|
+
def initialize(nom, prot, gluc, lip, gluc_data = nil)
|
|
6
|
+
@nom = nom
|
|
7
|
+
@prot = prot
|
|
8
|
+
@gluc = gluc
|
|
9
|
+
@lip = lip
|
|
10
|
+
@gluc_data = gluc_data
|
|
11
|
+
@cal_index = (@prot.to_f*4 + @gluc.to_f*4 + @lip.to_f*9).round(2)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Muestra la información de un alimento en concreto
|
|
15
|
+
def to_s
|
|
16
|
+
#El huevo frito tiene 14.1 proteinas, 0.0 glúcidos, 19.5 lípidos
|
|
17
|
+
"%21s"%"#{@nom}:%13s "%" #{@prot} %13s "%" #{@gluc} %15s "%" #{@lip} %13s "%" #{@cal_index}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Se comprueba que no sea un valor negativo, en caso de serlo, se sustituye por un 0
|
|
21
|
+
def not_negative(n)
|
|
22
|
+
n < 0 ? n = 0 : n = n
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Calcula el área bajo la curva para los datos tomados en una medición de glucosa en intervalos de tiempo de 5 minutos
|
|
26
|
+
def aibc
|
|
27
|
+
@gluc_data.map{|indv| zero = indv.at(0); prev = -2; indv.map{|index| prev = prev + 1; ((index-zero) + (indv.at(not_negative(prev))-zero))*2.5}.reduce(:+).round(2)}
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/P11/plato.rb
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
class Plato
|
|
2
|
+
attr_reader :name, :total
|
|
3
|
+
def initialize(name, &block)
|
|
4
|
+
@name = name
|
|
5
|
+
@alimentos = []
|
|
6
|
+
@total = 0
|
|
7
|
+
|
|
8
|
+
if block_given?
|
|
9
|
+
if block.arity == 1
|
|
10
|
+
yield self
|
|
11
|
+
else
|
|
12
|
+
instance_eval(&block)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def convert_quantities(amount)
|
|
18
|
+
grams = 0
|
|
19
|
+
prop = 1
|
|
20
|
+
|
|
21
|
+
if amount[:porcion] =~ /taza/i
|
|
22
|
+
amount[:porcion] = amount[:porcion].gsub(/taz(a\s|as\s|a\z|as\z)/, '')
|
|
23
|
+
grams = 3
|
|
24
|
+
else if amount[:porcion] =~ /cucharada/i
|
|
25
|
+
amount[:porcion] = amount[:porcion].gsub(/cucharad(a\s|as\s|a\z|as\z)/, '')
|
|
26
|
+
grams = 0.09
|
|
27
|
+
|
|
28
|
+
else if amount[:porcion] =~ /cucharon/i
|
|
29
|
+
amount[:porcion] = amount[:porcion].gsub(/cucharo(n\s|nes\s|n\z|nes\z)/, '')
|
|
30
|
+
grams = 10
|
|
31
|
+
|
|
32
|
+
else if amount[:porcion] =~ /pieza/i
|
|
33
|
+
amount[:porcion] = amount[:porcion].gsub(/piez(a\s|as\s|a\z|as\z)/, '')
|
|
34
|
+
grams = 1
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
if amount[:porcion] =~ /pequeñ(a\s|as\s|a\z|as\z|o\s|os\s|o\z|os\z)/i
|
|
41
|
+
amount[:porcion] = amount[:porcion].gsub(/pequeñ(a\s|as\s|a\z|as\z|o\s|os\s|o\z|os\z)/, '')
|
|
42
|
+
grams = grams.to_f / 2
|
|
43
|
+
end
|
|
44
|
+
# reconoce numero y fraccion amount[:porcion] = amount[:porcion].match(/(\d\/\d)|\d/)
|
|
45
|
+
|
|
46
|
+
# Si el número es una fracción
|
|
47
|
+
if amount[:porcion].match(/(\d\/\d)/)
|
|
48
|
+
num = amount[:porcion].match(/(\d\/)/).to_s.gsub(/(\/)/, '').to_f
|
|
49
|
+
den = amount[:porcion].match(/(\/\d)/).to_s.gsub(/(\/)/, '').to_f
|
|
50
|
+
prop = num/den
|
|
51
|
+
else
|
|
52
|
+
# Si el numero es entero
|
|
53
|
+
prop = amount[:porcion].match(/\d/).to_s.to_i
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
grams = grams * prop
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def insert_food(name, amount)
|
|
60
|
+
food = Food[name]
|
|
61
|
+
|
|
62
|
+
if amount[:porcion]
|
|
63
|
+
quantity = Food[name].cal_index * convert_quantities(amount)
|
|
64
|
+
else
|
|
65
|
+
quantity = Food[name].cal_index * amount[:gramos]/10
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
@alimentos << [food, quantity.round(2)]
|
|
69
|
+
@total = @alimentos.map{|x| x[1]}.reduce(:+)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def vegetal(name, amount)
|
|
73
|
+
insert_food(name, amount)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def fruta(name, amount)
|
|
77
|
+
insert_food(name, amount)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def cereal(name, amount)
|
|
81
|
+
insert_food(name, amount)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def proteina(name, amount)
|
|
85
|
+
insert_food(name, amount)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def aceite(name, amount)
|
|
89
|
+
insert_food(name, amount)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def to_s
|
|
93
|
+
puts @name
|
|
94
|
+
|
|
95
|
+
i = 0
|
|
96
|
+
while(i < @name.size)
|
|
97
|
+
print "="
|
|
98
|
+
i = i + 1
|
|
99
|
+
end
|
|
100
|
+
puts
|
|
101
|
+
puts "Composición nutricional:"
|
|
102
|
+
puts " Glúcidos Proteínas Lípidos Valor energético Valor porcion"
|
|
103
|
+
|
|
104
|
+
@alimentos.map{|x| print x[0], "%8s" % x[1], "\n"}
|
|
105
|
+
print "Valor energético total: ", "%44s" % @total
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
end
|