menu_Alexandra 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.
@@ -0,0 +1,88 @@
1
+ #
2
+ # Clase Dieta para ver si una persona obtiene suficientes nutrientes
3
+ #
4
+ # @author [Alexandra]
5
+ #
6
+
7
+ module Nutri
8
+ class Dieta
9
+ include Comparable
10
+ #getter y setter
11
+ attr_accessor :food_energy, :gasto_energetico_total, :factor_actividad_fisica
12
+
13
+ #
14
+ # [initialize]
15
+ # @param patiente [Paciente] [description]
16
+ #
17
+ # @return [type] [description]
18
+ def initialize(paciente)
19
+ @peso_teorico_ideal = (paciente.talla - 150) * 0.75 + 50
20
+ @gasto_energetico_basal = (10 * paciente.peso) + (6.25 * paciente.talla) - (5 * paciente.edad) + ((paciente.sexo==1)? -161 : 5)
21
+ @efecto_termogeno = @gasto_energetico_basal * 0.1
22
+ @factor_actividad_fisica = 0.0
23
+ @gasto_actividad_fisica = @gasto_energetico_basal * @factor_actividad_fisica
24
+ @gasto_energetico_total = @gasto_energetico_basal * @efecto_termogeno + @gasto_actividad_fisica
25
+ @food = Listas.new()
26
+ @food_energy = 0.0
27
+ end
28
+
29
+ #
30
+ # [add eaten item to food]
31
+ # @param item [Nutri] [Item what was eate]
32
+ #
33
+ # @return [] [no return]
34
+ def eat(item)
35
+ @food.push(item)
36
+ @food_energy = @food.reduce(0) { |sum, obj| sum + obj.energia.to_i }
37
+ end
38
+
39
+ #
40
+ # [change factor of phys activity]
41
+ # @param intensity [int] [intensity from 0 to 3]
42
+ #
43
+ # @return [] [no return]
44
+ def sport(intensity)
45
+
46
+ if intensity == 0 || intensity == "reposo"
47
+ @factor_actividad_fisica = 0.0
48
+ elsif intensity == 1 || intensity == "ligera"
49
+ @factor_actividad_fisica = 0.12
50
+ elsif intensity == 2 || intensity == "moderada"
51
+ @factor_actividad_fisica = 0.27
52
+ elsif intensity == 3 || intensity == "intensa"
53
+ @factor_actividad_fisica = 0.54
54
+ end
55
+
56
+ @gasto_actividad_fisica = @gasto_energetico_basal * @factor_actividad_fisica
57
+ @gasto_energetico_total = @gasto_energetico_basal * @efecto_termogeno + @gasto_actividad_fisica
58
+ return @factor_actividad_fisica
59
+ end
60
+
61
+ #
62
+ # Analize function Analizes all the data and calculates, wheater the consumed food was enough or even too much.
63
+ #
64
+ # @return [string] [Returns a nice readeable output with the evaluated data and the result.]
65
+
66
+ #
67
+ # [analize given data and calculate if patientes consumed food was enough or too much for his phys activity]
68
+ #
69
+ # @return [string] [too much/less/right]
70
+ def analize()
71
+ difference = @gasto_energetico_total - @food_energy
72
+ puts "Consumed Energy:\t#{@food_energy.round(2)}\nBurned Energy:\t\t#{@gasto_energetico_total.round(2)}\n\n"
73
+ if difference.abs <= @gasto_energetico_total * 0.1
74
+ puts "La cantidad de la alimentación es suficiente para cubrir las exigencias calóricas del organismo y mantiene el equilibrio de su balance.\n Difference: #{difference.round(2)}"
75
+ elsif @food_energy < @gasto_energetico_total
76
+ puts "La cantidad de la alimentación no es suficiente para cubrir las exigencias calóricas del organismo.\nTomaste #{difference.round(2)}kcal/g muy poco."
77
+ elsif @food_energy > @gasto_energetico_total
78
+ puts "Ha consumido demasiado calóricas. No mantiene el equilibrio de su balance.\nTomaste #{difference.round(2)}kcal/g demasiado."
79
+ # else puts "Strange ERROR"
80
+ end
81
+ return difference
82
+ end
83
+ end
84
+
85
+ def <=> (other)
86
+ gasto_energetico_total <=> other.gasto_energetico_total
87
+ end
88
+ end
@@ -0,0 +1,133 @@
1
+ #
2
+ # [Clase etiqueta que representa la nutricion de una etiqueta de un alimento]
3
+ #
4
+ # @author [Alexandra]
5
+ module Nutri
6
+
7
+ class Etiqueta
8
+
9
+ include Comparable
10
+ #getters
11
+ attr_reader :nombre, :grasa , :grasas_saturadas, :hidratos, :azucares, :proteinas, :sal, :fibra, :energia
12
+ #setters
13
+ #attr_writer :nombre, :grasa , :grasas_saturadas, :hidratos, :azucares, :proteinas, :sal, :fibra
14
+
15
+
16
+
17
+ #
18
+ # [Inicializamos los objetos]
19
+ # @param nombre [string] [name]
20
+ # @param grasa [int] [ fat of obj as string]
21
+ # @param grasas_saturadas [int] [ saturates fat of obj as string]
22
+ # @param hidratos [int] [ hydrates of obj as string]
23
+ # @param azucares [int] [ sugar of obj as string]
24
+ # @param proteinas [int] [ protein of obj as string]
25
+ # @param sal [int] [ salt of obj as string]
26
+ # @param fibra [int] [ fiber of obj as string]
27
+ #
28
+ # @return [type] [description]
29
+ def initialize(nombre, grasa, grasas_saturadas, hidratos, azucares, proteinas, sal, fibra)
30
+ @nombre, @grasa, @grasas_saturadas, @hidratos, @azucares, @proteinas, @sal, @fibra = nombre, grasa, grasas_saturadas, hidratos, azucares, proteinas, sal, fibra
31
+ @energia = 0.0
32
+ valor_energetico()
33
+ end
34
+
35
+ #
36
+ # [converts attribute to srting]
37
+ #
38
+ # @return [string] [attr to string]
39
+ def nombre_to_s
40
+ "#{@nombre}\n"
41
+ end
42
+
43
+ #
44
+ # [converts attribute to srting]
45
+ #
46
+ # @return [string] [attr to string]
47
+ def grasa_to_s
48
+ "#{@grasa} kJ/g\n"
49
+ end
50
+
51
+ #
52
+ # [converts attribute to srting]
53
+ #
54
+ # @return [string] [attr to string]
55
+ def grasas_saturadas_to_s
56
+ "#{@grasas_saturadas} kJ/g\n"
57
+ end
58
+
59
+ #
60
+ # [converts attribute to srting]
61
+ #
62
+ # @return [string] [attr to string]
63
+ def hidratos_to_s
64
+ "#{@hidratos} kJ/g\n"
65
+ end
66
+
67
+ #
68
+ # [converts attribute to srting]
69
+ #
70
+ # @return [string] [attr to string]
71
+ def azucares_to_s
72
+ "#{@azucares} g\n"
73
+ end
74
+
75
+ #
76
+ # [converts attribute to srting]
77
+ #
78
+ # @return [string] [attr to string]
79
+ def proteinas_to_s
80
+ "#{@proteinas} g\n"
81
+ end
82
+
83
+ #
84
+ # [converts attribute to srting]
85
+ #
86
+ # @return [string] [attr to string]
87
+ def sal_to_s
88
+ "#{@sal} g\n"
89
+ end
90
+
91
+ #
92
+ # [calculates energy of the object]
93
+ #
94
+ # @return [string] [gives back energy in kJ/g and kcal/g]
95
+ def valor_energetico
96
+ v1 = [@grasa, @hidratos, @proteinas, @sal, @fibra]
97
+ v2 = [37, 17, 17, 25, 8]#Conversion en kJ/g
98
+ v3 = [9, 4, 4, 6, 2]#Conversion en kcal/g
99
+
100
+ s1 = 0
101
+ s2 = 0
102
+ i = 0
103
+ while (i < v1.length)
104
+ s1 += v1[i] * v2[i]
105
+ s2 += v1[i] * v3[i]
106
+ i += 1
107
+ end
108
+ @energia = s2
109
+ return "#{s1.round(2)} kJ/g y #{s2.round(2)} kcal/g\n"
110
+ end
111
+
112
+ #
113
+ # [converts attribute to srting]
114
+ #
115
+ # @return [string] [attr to string]
116
+ def formato_to_s
117
+ puts "Nombre de etiqueta: #{@nombre}, Grasas: #{@grasa}, Grasas saturadas: #{@grasas_saturadas}, Hidratos: #{@hidratos}, Azúcares: #{@azucares}, Proteinas: #{@proteinas}, Sal: #{@sal}, Fibra: #{@fibra}"
118
+ end
119
+
120
+ #
121
+ # Comparar los objetos con el azucar
122
+ # @param other [object] [Person object]
123
+ #
124
+ # @return [bool] [true or false]
125
+ def <=>(other)
126
+ #return nil unless other.instance_of? Nutri
127
+ @azucares <=> other.azucares
128
+ end
129
+
130
+
131
+ end
132
+ end
133
+
@@ -0,0 +1,167 @@
1
+ #
2
+ # Doubly Linked List
3
+ # Enumerable functions included
4
+ #
5
+ # @author [Alexandra]
6
+ #
7
+ Node = Struct.new(:prev, :value, :next)
8
+ class Listas
9
+ include Enumerable
10
+
11
+ attr_reader :size, :head, :tail
12
+
13
+ #
14
+ # Initialize
15
+ # Initializes all to nil
16
+ # @return [nil] [nothing]
17
+ def initialize()
18
+ @head = nil
19
+ @tail = nil
20
+ @size = 0
21
+ end
22
+
23
+ #
24
+ # Each Method, necessarie for the enumeration
25
+ #
26
+ # @return [obj.value] [gives back the value of the actual node]
27
+ def each()
28
+ act = @head
29
+ while act != nil
30
+ yield act.value
31
+ act = act.next
32
+ end
33
+ end
34
+
35
+ #
36
+ # Pushes a new Object at the end of the list.
37
+ # @param obj [object] [Object that should be placed at the end of the list.]
38
+ #
39
+ # @return [string] [Returns the String of the Object]
40
+ def push(obj)
41
+ a = Node.new(obj, nil, @tail)
42
+ if size > 0
43
+ @tail.next = a
44
+ else
45
+ @head = a
46
+ end
47
+ @tail = a
48
+ @size += 1
49
+ return a.value.to_s
50
+ end
51
+ =begin
52
+ def pushb(obj)
53
+ a = Node.new(obj, @head, nil)
54
+ if size > 0
55
+ @head.prev = a
56
+ else
57
+ @tail = a
58
+ end
59
+ @head = a
60
+ @size += 1
61
+ return a.value.to_s
62
+ end
63
+ =end
64
+ #
65
+ # Pops the last Element of the list and prints it via the to_s method.
66
+ #
67
+ # @return [string] [Returns the String of the Object]
68
+ def pop()
69
+ if size > 0
70
+ a = @tail.value
71
+ @size -= 1
72
+ @tail = @tail.prev
73
+ if size > 0
74
+ @tail.next = nil
75
+ else
76
+ @head = nil
77
+ end
78
+ else
79
+ puts "No elements"
80
+ end
81
+ return a.to_s
82
+ end
83
+ =begin
84
+ def popb()
85
+ if size > 0
86
+ a = @head.value
87
+ @size -= 1
88
+ @head = @head.next
89
+ if size > 0
90
+ @head.prev = nil
91
+ else
92
+ @head = nil
93
+ end
94
+ else
95
+ puts "No elements"
96
+ end
97
+ return a.to_s
98
+ end
99
+ =end
100
+ def pushn(ar)
101
+ ar.each do |i|
102
+ push(i)
103
+ end
104
+ end
105
+
106
+ =begin
107
+ def pushbn(ar)
108
+ ar.each do |i|
109
+ pushb(i)
110
+ end
111
+ end
112
+ def popn(i)
113
+ while @size > 0 && i > 0 do
114
+ pop()
115
+ end
116
+ end
117
+ def popbn(i)
118
+ while @size > 0 && i > 0 do
119
+ popb()
120
+ end
121
+ end
122
+ =end
123
+
124
+ # Tarea 3
125
+ def for_listas
126
+ sorted = [@head.value]
127
+ act = @head
128
+ for i in (1...@size)
129
+ act = act.next
130
+ for j in (0..sorted.size)
131
+ if (j == sorted.size)
132
+ sorted.push(act.value)
133
+ elsif (act.value < sorted[j])
134
+ sorted.insert(j, act.value)
135
+ break
136
+ end
137
+ end
138
+ end
139
+ return sorted
140
+ end
141
+
142
+ # Tarea 4
143
+ def each_listas
144
+ sorted = [@head.value]
145
+ self.each_with_index do |x, pos_x|
146
+ if (pos_x != 0)
147
+ sorted.each_with_index do |y, pos_y|
148
+ if (pos_y == sorted.size - 1)
149
+ if (x < y)
150
+ sorted.insert(pos_y, x)
151
+ break
152
+ else
153
+ sorted.push(x)
154
+ break
155
+ end
156
+ elsif (x < y)
157
+ sorted.insert(pos_y, x)
158
+ break
159
+ end
160
+ end
161
+ end
162
+ end
163
+ return sorted
164
+ end
165
+
166
+
167
+ end
data/lib/nutri/menu.rb ADDED
@@ -0,0 +1,135 @@
1
+ class Menu
2
+ attr_accessor :dia, :titulo
3
+
4
+ def initialize(dia, titulo, &block)
5
+ @dia = dia
6
+ @titulo = titulo
7
+ @comida = []
8
+
9
+ @momento = []
10
+ @valor_energetico
11
+ @cont = 0
12
+ @v_total = 0
13
+ @tabla = [" ", "grasas", "carbohidratos", "proteinas", "fibra", "sal", "valor energetico"]
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 to_s
25
+
26
+ output = "#{@dia.ljust(15)} Menú:#{@titulo.ljust(30)} Composición Nutricional"
27
+ output << "\n#{'=' * 140}\n"
28
+
29
+ @tabla.each do |obj|
30
+ output << "#{obj.ljust(20)}"
31
+ end
32
+
33
+ output << "\n"
34
+
35
+ @comida.each do |obj|
36
+ if (@cont == 0)
37
+ if( @momento.include?(obj) == false )
38
+ output << "\n"
39
+ output << "#{obj}"
40
+ output << "\n"
41
+ @momento.push(obj)
42
+ @cont+=1
43
+ else
44
+ @cont+=1
45
+ end
46
+ else
47
+ output << "#{obj.ljust(20)}"
48
+ @cont+=1
49
+ end
50
+ if (@cont == 8)
51
+ output << "\n"
52
+ @cont = 0
53
+ end
54
+ end
55
+ output << "\n#{'=' * 140}\n"
56
+ output << "Valor energético total: "
57
+ output << " #{@v_total}"
58
+
59
+ output
60
+ end
61
+
62
+ def comida(nombre, opciones = {})
63
+ @comida << nombre
64
+ @comida << "'#{opciones[:descripcion]}'"
65
+ @comida << "#{opciones[:grasas]}"
66
+ @comida << "#{opciones[:carbohidratos]}"
67
+ @comida << "#{opciones[:proteinas]}"
68
+ @comida << "#{opciones[:fibra]}"
69
+ @comida << "#{opciones[:sal]}"
70
+ @valor_energetico = ((opciones[:grasas]*36) + (opciones[:carbohidratos]*17)+(opciones[:proteinas]*17)+(opciones[:sal]*25)).round(2)
71
+ @v_total += @valor_energetico
72
+ @comida << "#{@valor_energetico}"
73
+
74
+ end
75
+
76
+ end
77
+
78
+ menu = Menu.new("Lunes", "Menu saludable") do
79
+ comida "Desayuno", :descripcion => "Tostadas con mermelada",
80
+ :porcion => "2 tostadas",
81
+ :gramos => 1
82
+ :carbohidratos => 49.5,
83
+ :proteinas => 5,
84
+ :fibra => 1.8,
85
+ :sal => 0.1
86
+
87
+
88
+ comida "Desayuno", :descripcion => "Plátano",
89
+ :porcion => "1 pieza",
90
+ :gramos => 8,
91
+ :grasas => 0.8,
92
+ :carbohidratos => 4,
93
+ :proteinas => 10,
94
+ :fibra => 2.8,
95
+ :sal => 0.08
96
+
97
+ comida "Almuerzo", :descripcion => "Sopa de fideos",
98
+ :porcion => "1 plato",
99
+ :gramos => 180,
100
+ :grasas => 1.1,
101
+ :carbohidratos => 25,
102
+ :proteinas => 20,
103
+ :fibra => 9.8,
104
+ :sal => 0.9
105
+
106
+ comida "Almuerzo", :descripcion => "Berenjenas rellenas",
107
+ :porcion => "1 porción",
108
+ :gramos => 100,
109
+ :grasas => 3.5,
110
+ :carbohidratos => 48,
111
+ :proteinas => 16,
112
+ :fibra => 1.8,
113
+ :sal => 1.05
114
+
115
+ comida "Cena", :descripcion => "Batido de frutas",
116
+ :porcion => "1 vaso",
117
+ :gramos => 40,
118
+ :grasas => 0.6,
119
+ :carbohidratos => 12,
120
+ :proteinas => 10,
121
+ :fibra => 1.8,
122
+ :sal => 0.05
123
+
124
+ comida "Cena", :descripcion => "revuelto de judias",
125
+ :porcion => "1 plato",
126
+ :gramos => 60,
127
+ :grasas => 1.2,
128
+ :carbohidratos => 26,
129
+ :proteinas => 9,
130
+ :fibra => 1.7,
131
+ :sal => 0.25
132
+ end
133
+
134
+
135
+ puts menu