alu0101028163 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 +2 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +95 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/practica6.rb +14 -0
- data/lib/practica6/etiqueta.rb +195 -0
- data/lib/practica6/list.rb +178 -0
- data/lib/practica6/menu_dietetico.rb +246 -0
- data/lib/practica6/paciente.rb +13 -0
- data/lib/practica6/paciente_obeso.rb +55 -0
- data/lib/practica6/persona.rb +31 -0
- data/lib/practica6/pruebas_menu.rb +208 -0
- data/lib/practica6/registro.rb +167 -0
- data/lib/practica6/version.rb +3 -0
- data/practica6.gemspec +46 -0
- metadata +170 -0
@@ -0,0 +1,178 @@
|
|
1
|
+
class List
|
2
|
+
include Enumerable
|
3
|
+
attr_reader :head, :tail, :size
|
4
|
+
|
5
|
+
# @return [List] retorna una nueva instancia de Lista.
|
6
|
+
def initialize()
|
7
|
+
@head = nil
|
8
|
+
@tail = nil
|
9
|
+
@size = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
# @return [List] método each implementado para el correcto funcionamiento del módulo Enumerable.
|
13
|
+
def each()
|
14
|
+
head_aux = @head
|
15
|
+
while head_aux != nil do
|
16
|
+
yield head_aux.value
|
17
|
+
head_aux = head_aux.next
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param etiqueta [Etiqueta] Recibe como parámetro una etiqueta que pasará a ser el valor de un nodo construido a posteriori.
|
22
|
+
# @return [Number] Retorna el tamaño de la lista tras expandirse esta.
|
23
|
+
def push_back(etiqueta)
|
24
|
+
|
25
|
+
node = Struct.new(:prev, :next, :value).new(nil,nil,etiqueta)
|
26
|
+
|
27
|
+
if @size == 0
|
28
|
+
@tail = node
|
29
|
+
@head = node
|
30
|
+
else
|
31
|
+
aux = @tail
|
32
|
+
@tail = node
|
33
|
+
@tail.prev = aux
|
34
|
+
aux.next = tail
|
35
|
+
end
|
36
|
+
|
37
|
+
@size += 1
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
# @param etiqueta [Etiqueta] Recibe como parámetro una etiqueta que pasará a ser el valor de un nodo construido a posteriori.
|
42
|
+
# @return [Number] Retorna el tamaño de la lista tras expandirse esta.
|
43
|
+
def push_front(etiqueta)
|
44
|
+
|
45
|
+
node = Struct.new(:prev, :next, :value).new(nil,nil,etiqueta)
|
46
|
+
|
47
|
+
if @size == 0
|
48
|
+
@tail = node
|
49
|
+
@head = node
|
50
|
+
else
|
51
|
+
aux = @head
|
52
|
+
@head = node
|
53
|
+
@head.next = aux
|
54
|
+
aux.prev = @head
|
55
|
+
end
|
56
|
+
|
57
|
+
@size += 1
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
# @return [Number] Retorna el tamaño de la lista tras decrementarse esta.
|
62
|
+
def pop_front()
|
63
|
+
aux = @head
|
64
|
+
@head = @head.next
|
65
|
+
@head.prev = nil
|
66
|
+
aux.prev = nil
|
67
|
+
aux.next = nil
|
68
|
+
@size -= 1
|
69
|
+
end
|
70
|
+
|
71
|
+
# @return [Number] Retorna el tamaño de la lista tras decrementarse esta.
|
72
|
+
def pop_back()
|
73
|
+
aux = @tail
|
74
|
+
@tail = @tail.prev
|
75
|
+
@tail.next = nil
|
76
|
+
aux.next = nil
|
77
|
+
aux.prev = nil
|
78
|
+
@size -= 1
|
79
|
+
end
|
80
|
+
|
81
|
+
# @param position [Number] recibe como parámetro la posición de la lista a inspeccionar.
|
82
|
+
# @return [Struct] retorna un struct que en el que está encapsulado el nodo.
|
83
|
+
def [](position)
|
84
|
+
aux = @head
|
85
|
+
position.times do
|
86
|
+
aux = aux.next
|
87
|
+
end
|
88
|
+
aux
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param a [Struct] nodo a intercambiar.
|
92
|
+
# @param b [Struct] nodo a intercambiar.
|
93
|
+
# @return [Struct]
|
94
|
+
def swap(a,b)
|
95
|
+
|
96
|
+
if @size == 2
|
97
|
+
a.prev = b
|
98
|
+
b.next = a
|
99
|
+
@tail = a
|
100
|
+
@head = b
|
101
|
+
elsif a == @head
|
102
|
+
a.next = b.next
|
103
|
+
b.prev = nil
|
104
|
+
b.next.prev = a
|
105
|
+
a.prev = b
|
106
|
+
b.next = a
|
107
|
+
@head = b
|
108
|
+
elsif b == @tail
|
109
|
+
a.next = nil
|
110
|
+
b.prev = a.prev
|
111
|
+
a.prev.next = b
|
112
|
+
a.prev = b
|
113
|
+
b.next = a
|
114
|
+
@tail = a
|
115
|
+
else
|
116
|
+
a.next = b.next
|
117
|
+
b.prev = a.prev
|
118
|
+
a.prev.next = b
|
119
|
+
b.next.prev = a
|
120
|
+
a.prev = b
|
121
|
+
b.next = a
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
# @return [Struct]
|
129
|
+
def clasificar_etiquetas
|
130
|
+
ordenado = false
|
131
|
+
aux_ = @head
|
132
|
+
while ordenado != true do
|
133
|
+
ordenado = true
|
134
|
+
i = 0
|
135
|
+
aux = @head
|
136
|
+
(@size - 1).times do
|
137
|
+
if aux.value.sal > aux.next.value.sal
|
138
|
+
self.swap(aux, aux.next)
|
139
|
+
ordenado = false
|
140
|
+
aux = aux.prev
|
141
|
+
end
|
142
|
+
aux = aux.next
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
# @return [Struct]
|
149
|
+
def clasificar_imc
|
150
|
+
ordenado = false
|
151
|
+
aux_ = @head
|
152
|
+
while ordenado != true do
|
153
|
+
ordenado = true
|
154
|
+
i = 0
|
155
|
+
aux = @head
|
156
|
+
(@size - 1).times do
|
157
|
+
if aux.value.registro.imc > aux.next.value.registro.imc
|
158
|
+
self.swap(aux, aux.next)
|
159
|
+
ordenado = false
|
160
|
+
aux = aux.prev
|
161
|
+
end
|
162
|
+
aux = aux.next
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
# @return [String] retorna una cadena con la información de todos los nodos de la lista.
|
168
|
+
def to_s
|
169
|
+
aux_ = @head
|
170
|
+
s = ""
|
171
|
+
while aux_ != nil do
|
172
|
+
s << aux_.value.to_s
|
173
|
+
aux_ = aux_.next
|
174
|
+
end
|
175
|
+
s
|
176
|
+
end
|
177
|
+
|
178
|
+
end
|
@@ -0,0 +1,246 @@
|
|
1
|
+
class Menu
|
2
|
+
attr_reader :name, :titulo, :ingesta, :desayuno, :almuerzo, :cena, :v_energetico_total
|
3
|
+
def initialize(name, &block)
|
4
|
+
|
5
|
+
@name = name
|
6
|
+
@titulo = ""
|
7
|
+
@ingesta = [30,35]
|
8
|
+
@desayuno = []
|
9
|
+
@almuerzo = []
|
10
|
+
@cena = []
|
11
|
+
@v_energetico_total = 0
|
12
|
+
|
13
|
+
|
14
|
+
if block_given?
|
15
|
+
if block.arity == 1
|
16
|
+
yield self
|
17
|
+
else
|
18
|
+
instance_eval(&block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
|
27
|
+
output = "#{@name}\t\t\t\t"
|
28
|
+
output << "Composición Nutricional"
|
29
|
+
output << "\n#{'=' * @name.size * 12}\n"
|
30
|
+
output << "#{' ' * 32 }"
|
31
|
+
output << "grasas\tcarbohidratos\tproteinas fibra sal azucares valor energetico\n\n"
|
32
|
+
output << "Desayuno\n"
|
33
|
+
output << "#{@desayuno.join}\n"
|
34
|
+
output << "Almuerzo\n"
|
35
|
+
output << "#{@almuerzo.join}\n"
|
36
|
+
output << "Cena\n"
|
37
|
+
output << "#{@cena.join}\n"
|
38
|
+
output << "Valor Energetico Total: " << "#{@v_energetico_total}"
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def titulo(titulo)
|
43
|
+
@titulo = titulo
|
44
|
+
end
|
45
|
+
|
46
|
+
# def ingesta(options={})
|
47
|
+
# ingesta << "(#{options[:min]})" if options[:min]
|
48
|
+
# ingesta << "(#{options[:max]})" if optionsþ[:max]
|
49
|
+
# @ingesta << ingesta
|
50
|
+
# end
|
51
|
+
|
52
|
+
def ingesta(options={})
|
53
|
+
@ingesta[0] = options[:min]
|
54
|
+
@ingesta[1] = options[:max]
|
55
|
+
end
|
56
|
+
|
57
|
+
def calcular_valor_energetico(ingredientes)
|
58
|
+
valor_energetico = 0
|
59
|
+
valor_energetico += ingredientes[:grasas] * 9
|
60
|
+
valor_energetico += ingredientes[:carbohidratos] * 4
|
61
|
+
valor_energetico += ingredientes[:azucares] * 4
|
62
|
+
valor_energetico += ingredientes[:fibra] * 2
|
63
|
+
valor_energetico += ingredientes[:proteinas] * 4
|
64
|
+
valor_energetico += ingredientes[:sal] * 6
|
65
|
+
end
|
66
|
+
|
67
|
+
def desayuno(options={})
|
68
|
+
hash = options
|
69
|
+
desayuno=""
|
70
|
+
desayuno << "\"#{options[:descripcion]}\"" if options[:descripcion]
|
71
|
+
desayuno << "#{' ' * ( 32 - options[:descripcion].size ) }"
|
72
|
+
# desayuno << "#{options[:porcion]}" if options[:porcion]
|
73
|
+
# desayuno << "#{options[:gramos]}" if options[:gramos]
|
74
|
+
if options[:grasas]
|
75
|
+
desayuno << "#{options[:grasas]}".ljust(6)
|
76
|
+
else
|
77
|
+
desayuno << "".ljust(6)
|
78
|
+
hash[:grasas] = 0
|
79
|
+
end
|
80
|
+
|
81
|
+
if options[:carbohidratos]
|
82
|
+
desayuno << "#{options[:carbohidratos]}".ljust(16)
|
83
|
+
else
|
84
|
+
desayuno << "".ljust(16)
|
85
|
+
hash[:carbohidratos] = 0
|
86
|
+
end
|
87
|
+
|
88
|
+
if options[:proteinas]
|
89
|
+
desayuno << "#{options[:proteinas]}".ljust(11)
|
90
|
+
else
|
91
|
+
desayuno << "".ljust(11)
|
92
|
+
hash[:proteinas] = 0
|
93
|
+
end
|
94
|
+
|
95
|
+
if options[:fibra]
|
96
|
+
desayuno << "#{options[:fibra]}".ljust(7)
|
97
|
+
else
|
98
|
+
desayuno << "".ljust(7)
|
99
|
+
hash[:fibra] = 0
|
100
|
+
end
|
101
|
+
|
102
|
+
if options[:sal]
|
103
|
+
desayuno << "#{options[:sal]}".ljust(8)
|
104
|
+
else
|
105
|
+
desayuno << "".ljust(8)
|
106
|
+
hash[:sal] = 0
|
107
|
+
end
|
108
|
+
|
109
|
+
if options[:azucares]
|
110
|
+
desayuno << "#{options[:azucares]}".ljust(12)
|
111
|
+
else
|
112
|
+
desayuno << "".ljust(12)
|
113
|
+
hash[:azucares] = 0
|
114
|
+
end
|
115
|
+
|
116
|
+
valor_energetico = calcular_valor_energetico(hash)
|
117
|
+
@v_energetico_total += valor_energetico
|
118
|
+
desayuno << "#{valor_energetico.round(2)}"
|
119
|
+
desayuno << "\n"
|
120
|
+
|
121
|
+
@desayuno << desayuno
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
def almuerzo(options={})
|
126
|
+
hash = options
|
127
|
+
almuerzo=""
|
128
|
+
almuerzo << "\"#{options[:descripcion]}\"" if options[:descripcion]
|
129
|
+
almuerzo << "#{' ' * ( 32 - options[:descripcion].size ) }"
|
130
|
+
# almuerzo << "#{options[:porcion]}" if options[:porcion]
|
131
|
+
# almuerzo << "#{options[:gramos]}" if options[:gramos]
|
132
|
+
if options[:grasas]
|
133
|
+
almuerzo << "#{options[:grasas]}".ljust(6)
|
134
|
+
else
|
135
|
+
almuerzo << "".ljust(6)
|
136
|
+
hash[:grasas] = 0
|
137
|
+
end
|
138
|
+
|
139
|
+
if options[:carbohidratos]
|
140
|
+
almuerzo << "#{options[:carbohidratos]}".ljust(16)
|
141
|
+
else
|
142
|
+
almuerzo << "".ljust(16)
|
143
|
+
hash[:carbohidratos] = 0
|
144
|
+
end
|
145
|
+
|
146
|
+
if options[:proteinas]
|
147
|
+
almuerzo << "#{options[:proteinas]}".ljust(11)
|
148
|
+
else
|
149
|
+
almuerzo << "".ljust(11)
|
150
|
+
hash[:proteinas] = 0
|
151
|
+
end
|
152
|
+
|
153
|
+
if options[:fibra]
|
154
|
+
almuerzo << "#{options[:fibra]}".ljust(7)
|
155
|
+
else
|
156
|
+
almuerzo << "".ljust(7)
|
157
|
+
hash[:fibra] = 0
|
158
|
+
end
|
159
|
+
|
160
|
+
if options[:sal]
|
161
|
+
almuerzo << "#{options[:sal]}".ljust(8)
|
162
|
+
else
|
163
|
+
almuerzo << "".ljust(8)
|
164
|
+
hash[:sal] = 0
|
165
|
+
end
|
166
|
+
|
167
|
+
if options[:azucares]
|
168
|
+
almuerzo << "#{options[:azucares]}".ljust(12)
|
169
|
+
else
|
170
|
+
almuerzo << "".ljust(12)
|
171
|
+
hash[:azucares] = 0
|
172
|
+
end
|
173
|
+
|
174
|
+
valor_energetico = calcular_valor_energetico(hash)
|
175
|
+
@v_energetico_total += valor_energetico
|
176
|
+
almuerzo << "#{valor_energetico.round(2)}"
|
177
|
+
almuerzo << "\n"
|
178
|
+
|
179
|
+
@almuerzo << almuerzo
|
180
|
+
end
|
181
|
+
|
182
|
+
def cena(options={})
|
183
|
+
hash = options
|
184
|
+
cena=""
|
185
|
+
cena << "\"#{options[:descripcion]}\"" if options[:descripcion]
|
186
|
+
cena << "#{' ' * ( 32 - options[:descripcion].size ) }"
|
187
|
+
# cena << "#{options[:porcion]}" if options[:porcion]
|
188
|
+
# cena << "#{options[:gramos]}" if options[:gramos]
|
189
|
+
if options[:grasas]
|
190
|
+
cena << "#{options[:grasas]}".ljust(6)
|
191
|
+
else
|
192
|
+
cena << "".ljust(6)
|
193
|
+
hash[:grasas] = 0
|
194
|
+
end
|
195
|
+
|
196
|
+
if options[:carbohidratos]
|
197
|
+
cena << "#{options[:carbohidratos]}".ljust(16)
|
198
|
+
else
|
199
|
+
cena << "".ljust(16)
|
200
|
+
hash[:carbohidratos] = 0
|
201
|
+
end
|
202
|
+
|
203
|
+
if options[:proteinas]
|
204
|
+
cena << "#{options[:proteinas]}".ljust(11)
|
205
|
+
else
|
206
|
+
cena << "".ljust(11)
|
207
|
+
hash[:proteinas] = 0
|
208
|
+
end
|
209
|
+
|
210
|
+
if options[:fibra]
|
211
|
+
cena << "#{options[:fibra]}".ljust(7)
|
212
|
+
else
|
213
|
+
cena << "".ljust(7)
|
214
|
+
hash[:fibra] = 0
|
215
|
+
end
|
216
|
+
|
217
|
+
if options[:sal]
|
218
|
+
cena << "#{options[:sal]}".ljust(8)
|
219
|
+
else
|
220
|
+
cena << "".ljust(8)
|
221
|
+
hash[:sal] = 0
|
222
|
+
end
|
223
|
+
|
224
|
+
if options[:azucares]
|
225
|
+
cena << "#{options[:azucares]}".ljust(12)
|
226
|
+
else
|
227
|
+
cena << "".ljust(12)
|
228
|
+
hash[:azucares] = 0
|
229
|
+
end
|
230
|
+
|
231
|
+
valor_energetico = calcular_valor_energetico(hash)
|
232
|
+
@v_energetico_total += valor_energetico
|
233
|
+
cena << "#{valor_energetico.round(2)}"
|
234
|
+
cena << "\n"
|
235
|
+
|
236
|
+
@cena << cena
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
end
|
241
|
+
|
242
|
+
|
243
|
+
# menu = Menu.new("Lunes") do
|
244
|
+
# titulo "Bajo en calorias"
|
245
|
+
# ingesta :min => 30, :max => 35
|
246
|
+
# end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Paciente < Persona
|
2
|
+
|
3
|
+
# @param nombre [number] nombre del paciente.
|
4
|
+
# @param peso [number] peso del paciente.
|
5
|
+
# @param talla [number] altura del paciente en metros.
|
6
|
+
# @param edad [number] edad del paciente.
|
7
|
+
# @param sexo [number] sexo del paciente, 0 corresponde a hombre y 1 a mujer.
|
8
|
+
# @return [Paciente] retorna una instancia de la clase Paciente.
|
9
|
+
def initialize(nombre, peso, talla, edad, sexo)
|
10
|
+
super(nombre, peso, talla, edad, sexo)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
class Paciente_obeso < Paciente
|
3
|
+
|
4
|
+
attr_reader :cir_cintura, :cir_cadera, :cir_brazo, :pl_tricipital, :pl_bicipital, :pl_subescapular, :pl_suprailiaco, :registro
|
5
|
+
|
6
|
+
# @param nombre [number] nombre del paciente.
|
7
|
+
# @param peso [number] peso del paciente.
|
8
|
+
# @param talla [number] altura del paciente en metros.
|
9
|
+
# @param edad [number] edad del paciente.
|
10
|
+
# @param sexo [number] sexo del paciente, 0 corresponde a hombre y 1 a mujer.
|
11
|
+
# @param cir_cintura [Number] circunferencia de la cintura del paciente.
|
12
|
+
# @param cir_cadera [Number] circunferencia de la cadera del paciente.
|
13
|
+
# @param cir_brazo [Number] circunferencia del brazo del paciente.
|
14
|
+
# @param pl_tricipital [Number] longitud del pliege tricipital del pariente.
|
15
|
+
# @param pl_bicipital [Number] longitud del pliege bicipital del pariente.
|
16
|
+
# @param pl_subescapular [Number] longitud del pliege subescapular del pariente.
|
17
|
+
# @param pl_suprailiaco [Number] longitud del pliege suprailiaco del pariente.
|
18
|
+
# @return [Paciente_Obeso] retorna una instancia del Paciente_Obeso.
|
19
|
+
def initialize(nombre, peso, talla, edad, sexo, cir_cintura, cir_cadera, cir_brazo, pl_tricipital, pl_bicipital, pl_subescapular, pl_suprailiaco)
|
20
|
+
super(nombre, peso, talla, edad, sexo)
|
21
|
+
@cir_cintura = cir_cintura
|
22
|
+
@cir_cadera = cir_cadera
|
23
|
+
@cir_brazo = cir_brazo
|
24
|
+
@pl_tricipital = pl_tricipital
|
25
|
+
@pl_bicipital = pl_bicipital
|
26
|
+
@pl_subescapular = pl_subescapular
|
27
|
+
@pl_suprailiaco = pl_suprailiaco
|
28
|
+
@registro = Registro.new(nombre, peso, talla, edad, sexo, cir_cintura, cir_cadera, cir_brazo, pl_tricipital, pl_bicipital, pl_subescapular, pl_suprailiaco)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [String] retorna una cadena con la información del paciente obeso.
|
32
|
+
def to_s
|
33
|
+
s = "Nombre: #{@nombre}
|
34
|
+
Peso: #{@peso}
|
35
|
+
Altura: #{@talla}
|
36
|
+
Edad: #{@edad}
|
37
|
+
"
|
38
|
+
if @sexo == 0
|
39
|
+
s << "Sexo: Hombre"
|
40
|
+
else s << "Sexo: Mujer"
|
41
|
+
end
|
42
|
+
|
43
|
+
s << "
|
44
|
+
Circunferencia cintura: #{@cir_cintura}
|
45
|
+
Circunferencia cadera: #{@cir_cadera}
|
46
|
+
Circunferencia brazo: #{@cir_brazo}
|
47
|
+
Pliegue tricipital: #{@pl_tricipital}
|
48
|
+
Pliegue bicipital: #{@pl_bicipital}
|
49
|
+
Pliegue subescapular: #{@pl_subescapular}
|
50
|
+
Pliegue suprailiaco: #{@pl_suprailiaco}"
|
51
|
+
|
52
|
+
s
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|