menuNutrientes 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.
data/lib/Individuo.rb ADDED
@@ -0,0 +1,186 @@
1
+ # @author Carlos Arvelo Garcia (alu0100943849)
2
+
3
+ require 'nutrientes/version'
4
+ require 'Antropometrico'
5
+
6
+ #Clase Individuo almacena los datos de un individuo
7
+
8
+ class Individuo
9
+
10
+ include Comparable
11
+
12
+ attr_reader :nombre
13
+
14
+ def initialize(nombre)
15
+ @nombre = nombre
16
+ @datos = nil
17
+ end
18
+
19
+ # Comprueba si el Tipo de un objeto es de tipo Individuo
20
+ #
21
+ # == Parameters:
22
+ # Recibe un objeto
23
+ #
24
+ # == Returns:
25
+ # Retorna true o false
26
+ def es(other)
27
+ if other.is_a? Individuo
28
+ @nombre == other.nombre
29
+ elsif
30
+ false
31
+ end
32
+ end
33
+
34
+ # Define el metodo para imprimir por pantalla
35
+ #
36
+ # == Parameters:
37
+ # No recibe ninguno
38
+ #
39
+ # == Returns:
40
+ # Un string con el contenido de las variables
41
+ def to_s
42
+ "#{nombre}"
43
+ end
44
+
45
+
46
+ end
47
+
48
+ class Pacientes < Individuo
49
+
50
+ attr_reader :datos, :actividad_fisica
51
+
52
+ def initialize(nombre,datos, actividad_fisica)
53
+ super(nombre)
54
+ @datos = datos #datos antropometricos
55
+ @actividad_fisica = actividad_fisica
56
+ end
57
+
58
+ def ==(other)
59
+ if other.is_a? Individuo
60
+ nombre == other.nombre
61
+ elsif
62
+ false
63
+ end
64
+ end
65
+
66
+ # Comprueba entre que valores esta el icm de un pacuente y determina su estado corporal
67
+ #
68
+ # == Parameters:
69
+ # No recibe ninguno
70
+ #
71
+ # == Returns:
72
+ # Un string con el peso del paciente
73
+ def indice_corporal
74
+ if @datos.indice_masa_corporal <= 18.5
75
+ "Bajo peso"
76
+ elsif @datos.indice_masa_corporal > 18.5 and @datos.indice_masa_corporal <= 24.9
77
+ "Peso adecuado"
78
+ elsif @datos.indice_masa_corporal > 25.0 and @datos.indice_masa_corporal <= 29.9
79
+ "Sobrepeso"
80
+ elsif @datos.indice_masa_corporal > 30.0 and @datos.indice_masa_corporal <= 34.9
81
+ "Obesidad grado 1"
82
+ elsif @datos.indice_masa_corporal > 35.0 and @datos.indice_masa_corporal <= 39.9
83
+ "Obesidad grado 2"
84
+ elsif @datos.indice_masa_corporal > 40
85
+ "Obesidad grado 3"
86
+ end
87
+ end
88
+
89
+ # Define el metodo para calcular el peso teorico ideal
90
+ #
91
+ # == Parameters:
92
+ # No recibe ninguno
93
+ #
94
+ # == Returns:
95
+ # Un float con el resultado de la operacion
96
+ def peso_teorico_ideal
97
+ ((@datos.talla * 100) - 150) * 0.75 + 50
98
+ end
99
+
100
+ # Define el metodo para calcular el gasto_energetico_basal
101
+ #
102
+ # == Parameters:
103
+ # No recibe ninguno
104
+ #
105
+ # == Returns:
106
+ # Un float con el resultado de la operacion
107
+ def gasto_energetico_basal
108
+
109
+ if @datos.sexo == 0
110
+
111
+ (10 * @datos.peso) + (6.25 * @datos.talla) - (5 * @datos.edad) - 161
112
+
113
+ elsif @datos.sexo == 1
114
+
115
+ (10 * @datos.peso) + (6.25 * @datos.talla) - (5 * @datos.edad) + 5
116
+
117
+ end
118
+
119
+ end
120
+
121
+ # Define el metodo para calcular el efecto_termogeno
122
+ #
123
+ # == Parameters:
124
+ # No recibe ninguno
125
+ #
126
+ # == Returns:
127
+ # Un float con el resultado de la operacion
128
+ def efecto_termogeno
129
+
130
+ gasto_energetico_basal * 0.10
131
+
132
+ end
133
+
134
+ # Define el metodo para calcular el gasto_actividad_fisica
135
+ #
136
+ # == Parameters:
137
+ # No recibe ninguno
138
+ #
139
+ # == Returns:
140
+ # Un float con el resultado de la operacion
141
+ def gasto_actividad_fisica
142
+
143
+ if @actividad_fisica == "reposo"
144
+ gasto_energetico_basal * 0.0
145
+ elsif @actividad_fisica == "ligera"
146
+ gasto_energetico_basal * 0.12
147
+ elsif @actividad_fisica == "moderada"
148
+ gasto_energetico_basal * 0.27
149
+ elsif @actividad_fisica == "intensa"
150
+ gasto_energetico_basal * 0.54
151
+ end
152
+
153
+ end
154
+
155
+ # Define el metodo para calcular el gasto_energetico_total
156
+ #
157
+ # == Parameters:
158
+ # No recibe ninguno
159
+ #
160
+ # == Returns:
161
+ # Un float con el resultado de la operacion
162
+ def gasto_energetico_total
163
+
164
+ gasto_energetico_basal + efecto_termogeno + gasto_actividad_fisica
165
+
166
+ end
167
+
168
+ def <=>(other)
169
+ gasto_energetico_total <=> other.gasto_energetico_total
170
+ end
171
+
172
+ # Define el metodo para imprimir por pantalla
173
+ #
174
+ # == Parameters:
175
+ # No recibe ninguno
176
+ #
177
+ # == Returns:
178
+ # Un string con el contenido de las variables
179
+ def to_s
180
+ "#{@datos.indice_masa_corporal}"
181
+ end
182
+
183
+ end
184
+
185
+
186
+
data/lib/Menu.rb ADDED
@@ -0,0 +1,148 @@
1
+ class Menu
2
+
3
+ attr_accessor :dia, :titulo_menu, :tiempo_comida, :desayunos, :comidas, :cenas, :val_ener, :vet
4
+
5
+ def initialize(dia, &block)
6
+ @dia = dia
7
+ @titulo_menu = nil
8
+ @tiempo_comida = []
9
+ @desayunos = []
10
+ @comidas = []
11
+ @cenas = []
12
+ @val_ener = nil
13
+ @vet = 0
14
+
15
+ if block_given?
16
+ if block.arity == 1
17
+ yield self
18
+ else
19
+ instance_eval(&block)
20
+ end
21
+ end
22
+ end
23
+
24
+ def titulo(nombre)
25
+ @titulo_menu = nombre
26
+ end
27
+
28
+ def valor_energetico(grasas, carbohidratos, proteinas, fibra, sal)
29
+ if grasas == nil then grasas = 0 end
30
+ if carbohidratos == nil then carbohidratos = 0 end
31
+ if proteinas == nil then proteinas = 0 end
32
+ if fibra == nil then fibra = 0 end
33
+ if sal == nil then sal = 0 end
34
+
35
+ @val_ener = (grasas * 9) + (carbohidratos * 4) + (proteinas * 4) + (fibra * 4) + (sal * 6)
36
+ @vet += @val_ener
37
+ end
38
+
39
+ def ingesta(options = {})
40
+ time = " #{options[:min]}" if options[:min]
41
+ time << " #{options[:max]}" if options[:max]
42
+
43
+ @tiempo_comida << time
44
+ end
45
+
46
+ def desayuno(options = {})
47
+ breakfast = sprintf(" %-25s", "\"#{options[:descripcion]}\"")
48
+ breakfast << sprintf(" %-15s", "#{options[:porcion]}")
49
+ breakfast << sprintf(" %-10s", "#{options[:gramos]}")
50
+ breakfast << sprintf(" %-10s", "#{options[:grasas]}")
51
+ breakfast << sprintf(" %-15s", "#{options[:carbohidratos]}")
52
+ breakfast << sprintf(" %-12s", "#{options[:proteinas]}")
53
+ breakfast << sprintf(" %-8s", " #{options[:fibra]}")
54
+ breakfast << sprintf(" %-7s", "#{options[:sal]}")
55
+
56
+ valor_energetico(options[:grasas], options[:carbohidratos], options[:proteinas], options[:fibra], options[:sal])
57
+ breakfast << sprintf(" %-10s", "#{@val_ener}")
58
+
59
+ @desayunos << breakfast
60
+ end
61
+
62
+ def comida(options = {})
63
+ meal = sprintf(" %-25s", "\"#{options[:descripcion]}\"")
64
+ meal << sprintf(" %-15s", "#{options[:porcion]}")
65
+ meal << sprintf(" %-10s", "#{options[:gramos]}")
66
+ meal << sprintf(" %-10s", "#{options[:grasas]}")
67
+ meal << sprintf(" %-15s", "#{options[:carbohidratos]}")
68
+ meal << sprintf(" %-12s", "#{options[:proteinas]}")
69
+ meal << sprintf(" %-8s", " #{options[:fibra]}")
70
+ meal << sprintf(" %-7s", "#{options[:sal]}")
71
+
72
+ valor_energetico(options[:grasas], options[:carbohidratos], options[:proteinas], options[:fibra], options[:sal])
73
+ meal << sprintf(" %-10s", "#{@val_ener}")
74
+
75
+ @comidas << meal
76
+ end
77
+
78
+ def cena(options = {})
79
+ dinner = sprintf(" %-25s", "\"#{options[:descripcion]}\"")
80
+ dinner << sprintf(" %-15s", "#{options[:porcion]}")
81
+ dinner << sprintf(" %-10s", "#{options[:gramos]}")
82
+ dinner << sprintf(" %-10s", "#{options[:grasas]}")
83
+ dinner << sprintf(" %-15s", "#{options[:carbohidratos]}")
84
+ dinner << sprintf(" %-12s", "#{options[:proteinas]}")
85
+ dinner << sprintf(" %-8s", " #{options[:fibra]}")
86
+ dinner << sprintf(" %-7s", "#{options[:sal]}")
87
+
88
+ valor_energetico(options[:grasas], options[:carbohidratos], options[:proteinas], options[:fibra], options[:sal])
89
+ dinner << sprintf(" %-10s", "#{@val_ener}")
90
+
91
+ @cenas << dinner
92
+ end
93
+
94
+ def to_s
95
+
96
+ cout = "\n" + @dia + " " + @titulo_menu + " Composicion nutricional"
97
+ cout << "\n#{'=' * cout.size}\n"
98
+
99
+ header=sprintf("%34s %14s %10s %17s %12s %7s %6s %20s\n","porcion", "gramos", "grasas", "carbohidratos", "proteinas", "fibra", "sal", "valor energetico")
100
+
101
+ cout << header
102
+ cout << "Desayuno\n"
103
+ @desayunos.each do |aux|
104
+ cout << "#{aux}\n"
105
+ end
106
+
107
+ cout << "\ncomida\n"
108
+ @comidas.each do |aux2|
109
+ cout << "#{aux2}\n"
110
+ end
111
+
112
+ cout << "\ncena\n"
113
+ @cenas.each do |aux3|
114
+ cout << "#{aux3}\n"
115
+ end
116
+
117
+ cout << "\nvalor energetico total #{@vet.round(2)}" + "\n"
118
+ cout
119
+
120
+ end
121
+
122
+ def printm
123
+ cout = "\n" + @dia + " " + @titulo_menu + " Composicion nutricional"
124
+ cout << "\n#{'=' * cout.size}\n"
125
+
126
+ header=sprintf("%34s %14s %10s %17s %12s %7s %6s %20s\n","porcion", "gramos", "grasas", "carbohidratos", "proteinas", "fibra", "sal", "valor energetico")
127
+
128
+ cout << header
129
+ cout << "Desayuno\n"
130
+ @desayunos.each do |aux|
131
+ cout << "#{aux}\n"
132
+ end
133
+
134
+ cout << "\ncomida\n"
135
+ @comidas.each do |aux2|
136
+ cout << "#{aux2}\n"
137
+ end
138
+
139
+ cout << "\ncena\n"
140
+ @cenas.each do |aux3|
141
+ cout << "#{aux3}\n"
142
+ end
143
+
144
+ cout << "\nvalor energetico total #{@vet.round(2)}" + "\n"
145
+ puts cout
146
+ end
147
+
148
+ end
@@ -0,0 +1,172 @@
1
+ # @author Carlos Arvelo Garcia (alu0100943849)
2
+
3
+ require 'nutrientes/version'
4
+ require 'DlinkedList'
5
+
6
+ #Clase Nutricional_label almacena los datos de los alimentos
7
+
8
+ class Nutricional_label
9
+
10
+ include Comparable
11
+
12
+ attr_reader :nombre_etiqueta, :grasa, :grasa_saturada, :hid_carbono, :azucares, :proteinas, :sal
13
+
14
+ def initialize(nombre_etiqueta,grasa,grasa_saturada,hid_carbono,azucares,proteinas,sal)
15
+ @nombre_etiqueta = nombre_etiqueta
16
+ @grasa = grasa
17
+ @grasa_saturada = grasa_saturada
18
+ @hid_carbono = hid_carbono
19
+ @azucares = azucares
20
+ @proteinas = proteinas
21
+ @sal = sal
22
+ end
23
+
24
+ # nombre de la comida
25
+ #
26
+ # == Parameters:
27
+ # No recibe parametros
28
+ #
29
+ # == Returns:
30
+ # el nombre de la etiqueta almacenado el la variable nombre_etiqueta
31
+ def label_name
32
+
33
+ "#{nombre_etiqueta}"
34
+
35
+ end
36
+
37
+ # Calcula el valor energetico de un alimento en KJ
38
+ #
39
+ # == Parameters:
40
+ # No recibe parametros
41
+ #
42
+ # == Returns:
43
+ # Una variable con el resultado de la operación
44
+ def energetic_value_KJ
45
+ @kj = (@grasa * 37) + (@grasa_saturada * 37) + (@hid_carbono * 17) + (@azucares * 17) + (@proteinas * 17) + (@sal * 25)
46
+ end
47
+
48
+ # Calcula el valor energetico de un alimento en Kcal
49
+ #
50
+ # == Parameters:
51
+ # No recibe parametros
52
+ #
53
+ # == Returns:
54
+ # Una variable con el resultado de la operación
55
+ def energetic_value_Kcal
56
+ @kcal = (@grasa * 9) + (@grasa_saturada * 9) + (@hid_carbono * 4) + (@azucares * 4) + (@proteinas * 4) + (@sal * 6)
57
+ end
58
+
59
+ # Imprime la etiqueta de informacion nutricional del alimento
60
+ #
61
+ # == Parameters:
62
+ # No recibe parametros
63
+ #
64
+ # == Returns:
65
+ # No retorna nada
66
+ def print_label
67
+ puts "#{@nombre_etiqueta}"
68
+ puts "\nValor energetico o nutriente | por 100g o 100ml de producto "
69
+ puts "--------------------------------|--------------------------------"
70
+ puts "valor energetico |" + " #{energetic_value_KJ}" + " KJ/" + "#{energetic_value_Kcal}" + " Kcal"
71
+ puts "Camtidad de grasas |" + " #{@grasa}g"
72
+ puts "Camtidad de grasas saturadas |" + " #{@grasa_saturada}g"
73
+ puts "Camtidad de hidratos de carbono |" + " #{@hid_carbono}g"
74
+ puts "Camtidad de azucares |" + " #{@azucares}g"
75
+ puts "Camtidad de proteinas |" + " #{@proteinas}g"
76
+ puts "Camtidad de sal |" + " #{@sal}g"
77
+ @nombre_etiqueta
78
+ end
79
+
80
+ # Define el metodo para compara elementos de tipo Nutricional_label
81
+ #
82
+ # == Parameters:
83
+ # Recibe un parametro de tipo Nutricional_label
84
+ #
85
+ # == Returns:
86
+ # Un valor booleano dependiendo del resultado de la operacion
87
+ def <=>(other)
88
+ energetic_value_Kcal <=> other.energetic_value_Kcal
89
+ end
90
+
91
+ # Indica la cantidad de sal que tiene el alimento
92
+ #
93
+ # == Parameters:
94
+ # Recibe un parametro de tipo Nutricional_label
95
+ #
96
+ # == Returns:
97
+ # Un string
98
+ def clasificar
99
+ if @sal <= 1
100
+ "poca"
101
+ elsif @sal > 1 and @sal <= 2
102
+ "media"
103
+ elsif @sal > 2
104
+ "mucha"
105
+ end
106
+ end
107
+
108
+ # Define el metodo para imprimir por pantalla
109
+ #
110
+ # == Parameters:
111
+ # No recibe ninguno
112
+ #
113
+ # == Returns:
114
+ # Un string con el contenido de las variables
115
+ def to_s
116
+
117
+ "#{@kcal}"
118
+
119
+ end
120
+
121
+ end
122
+
123
+
124
+ def ordenarArrayEach(lista_menus)
125
+ arrayOrd = []
126
+ lista_menus.each do |menus|
127
+ if arrayOrd.empty?
128
+ arrayOrd.push(menus)
129
+ else
130
+ indice = 0
131
+ while indice < arrayOrd.length
132
+ energia = menus.reduce(0) {|sum, val_ener| sum + val_ener.energetic_value_Kcal}
133
+ energia_siguiente = arrayOrd[indice].reduce(0) {|sum, val_ener| sum + val_ener.energetic_value_Kcal}
134
+ if energia <= energia_siguiente
135
+ arrayOrd.insert(indice, menus)
136
+ break
137
+ elsif indice == arrayOrd.length-1
138
+ arrayOrd.insert(indice+1, menus)
139
+ break
140
+ end
141
+ indice+=1
142
+ end
143
+ end
144
+ end
145
+ return arrayOrd
146
+
147
+ end
148
+
149
+ def ordenarArrayFor(lista_menus)
150
+ arrayOrd = []
151
+ for menus in lista_menus
152
+ if arrayOrd.empty?
153
+ arrayOrd.push(menus)
154
+ else
155
+ indice = 0
156
+ while indice < arrayOrd.length
157
+ energia = menus.reduce(0) {|sum, val_ener| sum + val_ener.energetic_value_Kcal}
158
+ energia_siguiente = arrayOrd[indice].reduce(0) {|sum, val_ener| sum + val_ener.energetic_value_Kcal}
159
+ if energia <= energia_siguiente
160
+ arrayOrd.insert(indice, menus)
161
+ break
162
+ elsif indice == arrayOrd.length-1
163
+ arrayOrd.insert(indice+1, menus)
164
+ break
165
+ end
166
+ indice+=1
167
+ end
168
+ end
169
+ end
170
+ return arrayOrd
171
+
172
+ end