prct060100890730 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,207 @@
1
+ require "prct06/version.rb"
2
+
3
+ class Plato
4
+ attr_accessor :nombre, :valor_calorico, :vegetales, :frutas, :cereales, :proteinas, :aceites
5
+
6
+ #@note Lista de alimentos para la costrucción de los platos
7
+ @@lista = Lista.new()
8
+ @HuevoFrito = AlimentoC.new("Huevo Frito", 14.1, 0.0, 19.5, "Huevos, lacteos y helados" )
9
+ @LecheVaca = AlimentoC.new("Leche vaca", 3.3, 4.8, 3.2, "Huevos, lacteos y helados")
10
+ @Yogurt = AlimentoC.new("Yogurt", 3.8, 4.9, 3.8, "Huevos, lacteos y helados")
11
+ @Cerdo = AlimentoC.new("Cerdo", 21.5, 0.0, 6.3, "Carnes y derivados")
12
+ @Ternera = AlimentoC.new("Ternera", 21.1, 0.0, 3.1, "Carnes y derivados")
13
+ @Pollo = AlimentoC.new("Pollo", 20.6, 0.0, 5.6, "Carnes y derivados")
14
+ @Bacalao = AlimentoC.new("Bacalao", 17.7, 0.0, 0.4, "Pescados y mariscos")
15
+ @Atun = AlimentoC.new("Atun", 21.5, 0.0, 15.5, "Pescados y mariscos")
16
+ @Salmon = AlimentoC.new("Salmon", 19.9, 0.0, 13.6, "Pescados y mariscos")
17
+ @AceiteOliva = AlimentoC.new("Aceite Oliva", 0.0, 0.2, 99.6, "Alimentos grasos")
18
+ @Mantequilla = AlimentoC.new("Mantequilla", 0.7, 0.0, 83.2, "Alimentos grasos")
19
+ @Chocolate = AlimentoC.new("Chocolate", 5.3, 47.0, 30.0, "Alimentos grasos")
20
+ @Azucar = AlimentoC.new("Azucar", 0.0, 99.8, 0.0, "Alimentos ricos en carbohidratos")
21
+ @Arroz = AlimentoC.new("Arroz",6.8, 77.7, 0.6, "Alimentos ricos en carbohidratos")
22
+ @Lentejas = AlimentoC.new("Lentejas", 23.5, 52.0, 1.4, "Alimentos ricos en carbohidratos")
23
+ @Papas = AlimentoC.new("Papas",2.0, 15.4, 0.1, "Alimentos ricos en carbohidratos")
24
+ @Tomate = AlimentoC.new("Tomate", 1.0, 3.5, 0.2, "Verduras y Hortalizas")
25
+ @Cebolla = AlimentoC.new("Cebolla", 1.3, 5.8, 0.3, "Verduras y Hortalizas")
26
+ @Calabaza = AlimentoC.new("Calabaza", 1.1, 4.8, 0.1, "Verduras y Hortalizas")
27
+ @Manzanas = AlimentoC.new("Manzanas", 0.3, 12.4, 0.4, "Frutas")
28
+ @Platanos = AlimentoC.new("Platanos", 1.2, 21.4, 0.2, "Frutas")
29
+ @Pera = AlimentoC.new("Pera", 0.5, 12.7, 0.3, "Frutas")
30
+
31
+ @nodo1 = Nodo.new(@HuevoFrito)
32
+ @nodo2 = Nodo.new(@LecheVaca)
33
+ @nodo3 = Nodo.new(@Yogurt)
34
+ @nodo4 = Nodo.new(@Cerdo)
35
+ @nodo5 = Nodo.new(@Ternera)
36
+ @nodo6 = Nodo.new(@Pollo)
37
+ @nodo7 = Nodo.new(@Bacalao)
38
+ @nodo8 = Nodo.new(@Atun)
39
+ @nodo9 = Nodo.new(@Salmon)
40
+ @nodo10 = Nodo.new(@AceiteOliva)
41
+ @nodo11 = Nodo.new(@Mantequilla)
42
+ @nodo12 = Nodo.new(@Chocolate)
43
+ @nodo13 = Nodo.new(@Azucar)
44
+ @nodo14 = Nodo.new(@Arroz)
45
+ @nodo15 = Nodo.new(@Lentejas)
46
+ @nodo16 = Nodo.new(@Papas)
47
+ @nodo17 = Nodo.new(@Tomate)
48
+ @nodo18 = Nodo.new(@Cebolla)
49
+ @nodo19 = Nodo.new(@Calabaza)
50
+ @nodo20 = Nodo.new(@Manzanas)
51
+ @nodo21 = Nodo.new(@Platanos)
52
+ @nodo22 = Nodo.new(@Pera)
53
+
54
+ @@lista.insert_queue(@nodo1)
55
+ @@lista.insert_queue(@nodo2)
56
+ @@lista.insert_queue(@nodo3)
57
+ @@lista.insert_queue(@nodo4)
58
+ @@lista.insert_queue(@nodo5)
59
+ @@lista.insert_queue(@nodo6)
60
+ @@lista.insert_queue(@nodo7)
61
+ @@lista.insert_queue(@nodo8)
62
+ @@lista.insert_queue(@nodo9)
63
+ @@lista.insert_queue(@nodo10)
64
+ @@lista.insert_queue(@nodo11)
65
+ @@lista.insert_queue(@nodo13)
66
+ @@lista.insert_queue(@nodo14)
67
+ @@lista.insert_queue(@nodo15)
68
+ @@lista.insert_queue(@nodo16)
69
+ @@lista.insert_queue(@nodo17)
70
+ @@lista.insert_queue(@nodo18)
71
+ @@lista.insert_queue(@nodo19)
72
+ @@lista.insert_queue(@nodo20)
73
+ @@lista.insert_queue(@nodo21)
74
+ @@lista.insert_queue(@nodo22)
75
+
76
+ #@note La equivalencia de las diferentes palabras en gramos
77
+ @@equGram = { "cucharadas"=>1.8,"piezas pequeñas"=>7,"taza"=>6,"cucharón"=>4,"pieza"=>10,"cucharada"=>1.8, "piezas"=>10 }
78
+
79
+ def initialize nombreIn, &bloque
80
+ @nombre = nombreIn
81
+ @valor_calorico = 0
82
+
83
+ @vegetales = []
84
+ @frutas = []
85
+ @cereales = []
86
+ @proteinas = []
87
+ @aceites = []
88
+
89
+ instance_eval(&bloque)
90
+ end
91
+
92
+ #@note Función para añadir correctamente los vegetales desde dls
93
+ #@param nombre_al[String], opcion[String]
94
+ def vegetal nombre_al, opcion = {}
95
+ cant = 0
96
+ alimento = @@lista.detect { |i| nombre_al == i.nombre }
97
+ if opcion[:gramos]
98
+ cant = options[:gramos]
99
+ elsif opcion[:porcion]
100
+ cant = get_cant opcion[:porcion]
101
+ end
102
+ @valor_calorico += cant*alimento.valor_calorico
103
+ @vegetales.push([alimento, (cant*alimento.valor_calorico).round(3)])
104
+ end
105
+
106
+ #@note Función para la cantidad de alimento que añadimos al plato
107
+ #@param porcion[String]
108
+ def get_cant porcion
109
+ #La cantidad está en el primer caracter
110
+ num = porcion.split[0].to_r
111
+ cad = ""
112
+ #Formateamos correctamente la cadena
113
+ porcion.split[1..cad.length-1].each do |i|
114
+ cad += i + " "
115
+ end
116
+ cant = num * @@equGram[cad.chomp ' ']
117
+ end
118
+
119
+ #@note Función para añadir correctamente las frutas desde dls
120
+ #@param nombre_al[Strign], opcion[String]
121
+ def fruta nombre_al, opcion = {}
122
+ cant = 0
123
+ alimento = @@lista.detect { |i| nombre_al == i.nombre }
124
+ if opcion[:gramos]
125
+ cant = opcion[:gramos]
126
+ elsif opcion[:porcion]
127
+ cant = get_cant opcion[:porcion]
128
+ end
129
+ @valor_calorico += cant*alimento.valor_calorico
130
+ @frutas.push([alimento, (cant*alimento.valor_calorico).round(3)])
131
+ end
132
+
133
+ #@note Función para añadir correctamente los cereales desde dls
134
+ #@param nombre_alimento[Strign], opcion[String]
135
+ def cereal nombre_alimento, opcion = {}
136
+ cant = 0
137
+ alimento = @@lista.detect { |i| nombre_alimento == i.nombre }
138
+ if opcion[:gramos]
139
+ cant = opcion[:gramos]
140
+ elsif opcion[:porcion]
141
+ cant = get_cant opcion[:porcion]
142
+ end
143
+ @valor_calorico += cant*alimento.valor_calorico
144
+ @cereales.push([alimento, (cant*alimento.valor_calorico).round(3)])
145
+ end
146
+
147
+ #@note Función para añadir correctamente los proteinas desde dls
148
+ #@param nombre_al[Strign], opcio[String]
149
+ def proteina nombre_al, opcion = {}
150
+ cant = 0
151
+ alimento = @@lista.detect { |i| nombre_al == i.nombre }
152
+ if opcion[:gramos]
153
+ cant = opcion[:gramos]
154
+ elsif opcion[:porcion]
155
+ cant = get_cant opcion[:porcion]
156
+ end
157
+ @valor_calorico += cant*alimento.valor_calorico
158
+ @proteinas.push([alimento, (cant*alimento.valor_calorico).round(3)])
159
+ end
160
+
161
+ #@note Función para añadir correctamente el aceite desde dls
162
+ #@param nombre_al[Strign], opcion[String]
163
+ def aceite nombre_al, opcion = {}
164
+ cant = 0
165
+ alimento = @@lista.detect { |i| nombre_al == i.nombre }
166
+ if opcion[:gramos]
167
+ cant = opcion[:gramos]
168
+ elsif opcion[:porcion]
169
+ cant = get_cant opcion[:porcion]
170
+ end
171
+ @valor_calorico += cant*alimento.valor_calorico
172
+ @aceites.push([alimento, (cant*alimento.valor_calorico).round(3)])
173
+ end
174
+
175
+ #@note Función para mostrar el contenido de la lista.
176
+ #@return Lista formateada en una cadena para su visualización.
177
+ def to_s
178
+ salida = @nombre + "\n"
179
+ salida += "=============================================================\n"
180
+ salida += "Composición nutricional: \n"
181
+ salida += "\tglúcidos proteínas lípidos \tgrupo\t\t\t valor energético\n"
182
+
183
+ for i in 0..@vegetales.length-1 do
184
+ salida += @vegetales[i][0].to_s + "\t\t" + @vegetales[i][1].to_s + "\n"
185
+ end
186
+
187
+ for i in 0..@frutas.length-1 do
188
+ salida += @frutas[i][0].to_s + "\t\t" + @frutas[i][1].to_s + "\n"
189
+ end
190
+
191
+ for i in 0..@cereales.length-1 do
192
+ salida += @cereales[i][0].to_s + "\t\t" + @cereales[i][1].to_s + "\n"
193
+ end
194
+
195
+ for i in 0..@proteinas.length-1 do
196
+ salida += @proteinas[i][0].to_s + "\t\t" + @proteinas[i][1].to_s + "\n"
197
+ end
198
+
199
+ for i in 0..@aceites.length-1 do
200
+ salida += @aceites[i][0].to_s + "\t\t" + @aceites[i][1].to_s + "\n"
201
+ end
202
+
203
+ salida += "Valor energetico = " + valor_calorico.to_s
204
+ salida
205
+ end
206
+
207
+ end
@@ -0,0 +1,210 @@
1
+ #@author Cristina Garrido Amador
2
+ #@date November 2017
3
+ #@class Lista
4
+ #@brief This class is for have a list of aliments, which have next and previous, and the value
5
+
6
+ #Includes a new class which is node, fot conteins the information of the each value of the list
7
+ Nodo = Struct.new(:valor, :siguiente, :anterior)
8
+
9
+ class Lista
10
+
11
+ #Includes the module Enumerable
12
+ #It have tres values, head of the list, queue of the list and size of the list
13
+ attr_accessor :head, :queue, :tamanio
14
+ include Enumerable
15
+
16
+ #@return Lista type of the class
17
+ #@brief this method is for insert a new head at the list
18
+ def initialize
19
+ @head = nil
20
+ @queue = nil
21
+ @tamanio = 0
22
+ end
23
+
24
+ #@param nodo [Nodo]
25
+ #@return head of the node
26
+ def insert_head(nodo)
27
+ if empty
28
+ nodo[:siguiente] = nil
29
+ nodo[:anterior] = nil
30
+ @head = nodo
31
+ @queue = nodo
32
+ else
33
+ nodo[:siguiente] = @head
34
+ @head[:anterior] = nodo
35
+ nodo[:anterior] = nil
36
+ @head = nodo
37
+ end
38
+
39
+ @tamanio = @tamanio + 1
40
+
41
+ end
42
+
43
+ #@param nodo [Nodo]
44
+ #@return queue of the node
45
+ #@brief the method is for insert a new queue at the list
46
+ def insert_queue(nodo)
47
+ if empty
48
+ nodo[:siguiente] = nil
49
+ nodo[:anterior] = nil
50
+ @head = nodo
51
+ @queue = nodo
52
+ else
53
+ nodo[:siguiente] = nil
54
+ nodo[:anterior] = @queue
55
+ @queue[:siguiente] = nodo
56
+ @queue = nodo
57
+ end
58
+
59
+ @tamanio = @tamanio + 1
60
+ end
61
+
62
+ #@param nodo, index [Nodo], [Number]
63
+ #@return nodo
64
+ #@brief this method is for insert a new node at the list
65
+ def insert_plus(nodos, index)
66
+ #si el indice es 1, insertara por la cabeza
67
+ if(index == 1)
68
+ for i in 0..(nodos.length-1)
69
+ insert_head(nodos[i])
70
+ end
71
+ end
72
+ #Si el indice es 2, insertara por la cola
73
+ else if(index == 2)
74
+ for i in 0..(nodos.length-1)
75
+ insert_queue(nodos[i])
76
+ end
77
+ end
78
+ end
79
+
80
+ #@return head of the list
81
+ #@brief return the head of the list and pass the second value at the position of the head
82
+ def pop_head
83
+ if !empty
84
+ if @head == @queue
85
+ aux = @head
86
+ @head = nil
87
+ @queue = nil
88
+ else
89
+ aux = @head
90
+ @head = @head.siguiente
91
+ @head[:anterior] = nil
92
+ end
93
+
94
+ @tamanio = @tamanio -1
95
+ aux
96
+ end
97
+ end
98
+
99
+
100
+ #@return queue of the list
101
+ #@brief return the queue of the list and pass the penultimate value at the position of the head
102
+ def pop_queue
103
+ if !empty
104
+ if @queue == @head
105
+ aux = @queue
106
+ @head = nil
107
+ @queue = nil
108
+ else
109
+ aux = @queue
110
+ @queue =aux.anterior
111
+ @queue[:siguiente] = nil
112
+ end
113
+
114
+ @tamanio = @tamanio - 1
115
+ aux
116
+ end
117
+ end
118
+
119
+ #@return [String] the resulting of join all the information, value, next and previous
120
+ def to_s
121
+ aux = @head
122
+ s = ""
123
+ while aux.siguiente != nil
124
+ s += aux.valor.to_s + "\n"
125
+ aux = aux.siguiente
126
+ end
127
+ s += aux.valor.to_s
128
+
129
+ end
130
+
131
+ #return array
132
+ #@brief get a list this method convert that into an array
133
+ #param lista
134
+
135
+ def convertirArray(lista)
136
+ lista.map{ |y| y}
137
+ end
138
+
139
+ #return array
140
+ #@brief get a list and return an array in order
141
+ #param lista
142
+
143
+ def ordenarArray(lista)
144
+ auxiliar = lista.convertirArray(lista)
145
+ for i in 0..(auxiliar.length)do
146
+ for j in 0..(auxiliar.length-2) do
147
+ if auxiliar[j] > auxiliar[j+1]
148
+ temporal = auxiliar[j]
149
+ auxiliar[j] = auxiliar[j+1]
150
+ auxiliar[j+1] = temporal
151
+ end
152
+ end
153
+ end
154
+
155
+ return auxiliar
156
+ end
157
+
158
+
159
+ #return array
160
+ #@brief get a list and return an array in order
161
+ #param lista
162
+
163
+ def ordenandoEach(lista)
164
+ auxiliar = lista.convertirArray(lista)
165
+ indice = 0
166
+ auxiliar.each do |x|
167
+ auxiliar.each do |y|
168
+ if (indice < auxiliar.length-1)
169
+ if (auxiliar[indice] > auxiliar[indice+1])
170
+ temporal = auxiliar[indice]
171
+ auxiliar[indice] = auxiliar[indice+1]
172
+ auxiliar[indice+1] = temporal
173
+ end
174
+ end
175
+
176
+ indice = indice+1
177
+ end
178
+
179
+ indice = 0
180
+ end
181
+
182
+ return auxiliar
183
+ end
184
+
185
+ def ordenandoSort(lista)
186
+ auxiliar = lista.convertirArray(lista)
187
+ auxiliar.sort
188
+ end
189
+
190
+
191
+ #return true or false
192
+ #@brief tell the programmer if the list is empty or not
193
+ def empty
194
+ if tamanio == 0
195
+ true
196
+ else
197
+ false
198
+ end
199
+ end
200
+
201
+ #return node
202
+ def each
203
+ aux = @head
204
+ while aux != nil
205
+ yield aux.valor
206
+ aux = aux.siguiente
207
+ end
208
+ end
209
+
210
+ end
@@ -0,0 +1,81 @@
1
+ #@author Cristina Garrido Amador
2
+ #@date November 2017
3
+ #@class Alimento
4
+ #@brief This class calculate how many calories have the aliments
5
+
6
+ class Alimento
7
+
8
+ #Includes the module Comparable
9
+ #It have four values,name of the aliment, and the information of proteins, lipids and glucids
10
+ attr_accessor :nombre, :proteinas, :glucidos, :lipidos, :datos
11
+ include Comparable
12
+
13
+
14
+ #@param name, proteinas, glucidos, lipidos [String], [Number], [Number], [Number]
15
+ #@return Lista type of the class
16
+ #@brief this method is for insert a new head at the list
17
+ def initialize(nombre, proteinas, glucidos, lipidos)
18
+ @nombre = nombre
19
+ @proteinas = proteinas
20
+ @glucidos = glucidos
21
+ @lipidos = lipidos
22
+ end
23
+
24
+
25
+ #@param other [Alimento]
26
+ #@return Alimento type of the class
27
+ #@brief it is a method for know if the node that calls the method it's not equal at the param node.
28
+ def <=>(other) #operador !=
29
+ return nil unless other.is_a?Alimento #devuelve nil si no son de la clase Alimento los dos objetos
30
+ if valor_calorico == other.valor_calorico
31
+ return 0
32
+ else
33
+ if valor_calorico < other.valor_calorico
34
+ return -1 #devuelve true cuando es menor, y lo niega para conseguirlo negado, el operador < solo comprueba el menor
35
+ else
36
+ return 1 #devuelve true si es >
37
+ end
38
+ end
39
+ end
40
+
41
+ #@param other [Alimento]
42
+ #@return Alimento type of the class
43
+ #@brief it is a method for know if the node that calls the method it's equal at the param node.
44
+ def == (other)
45
+ if other.is_a?Alimento
46
+ valor_calorico == other.valor_calorico
47
+ else
48
+ false
49
+ end
50
+ end
51
+
52
+ #@return [String] the resulting of join all the information, name, proteins, glucids and lipids
53
+ def to_s
54
+ imprime = "#{@nombre}: #{@proteinas} #{@glucidos} #{@lipidos}"
55
+ end
56
+
57
+
58
+ #@return valor[Float]
59
+ #@brief it is a method for calculate the AIBC
60
+ def AIBC(indice) #indice = individuo
61
+ aux=[]
62
+ #zip --> coge dos vectores y genera pares, la pos 1 del vector 1 y la pos 2 del vector a los devuelve y los guardo en aux
63
+ #de esta forma tendre en x la pos actual y en y la pos-1 para llevar a cabo la formula
64
+ datos[indice][1..datos[indice].length - 1].zip(datos[indice][0..datos[indice].length - 2]) do |x,y|
65
+ if x < datos[indice][0]
66
+ aux << 0.0
67
+ else
68
+ aux << (((x-datos[indice][0])+(y-datos[indice][0]))/2)*5
69
+ end
70
+ end
71
+ aux.reduce(:+) #sumatorio del vector auxiliar, es lo que devuelve el metodo
72
+ end
73
+
74
+ #@return valor [Number]
75
+ #@brief it is a method that returns the value of calories of the aliment
76
+ def valor_calorico
77
+ valor = (@proteinas * 4) + (@glucidos * 4) + (@lipidos * 9)
78
+ end
79
+
80
+
81
+ end
@@ -0,0 +1,3 @@
1
+ module Prct06
2
+ VERSION = "0.1.0"
3
+ end
data/lib/prct06.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "prct06/version"
2
+
3
+ module Prct06
4
+ # Your code goes here...
5
+ end
data/prct06.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "prct06/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "prct060100890730"
8
+ spec.version = Prct06::VERSION
9
+ spec.authors = ["alu0100890730"]
10
+ spec.email = ["alu0100890730@ull.edu.es"]
11
+
12
+ spec.summary = %q{Calcular el valor calorico}
13
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1718/tdd-alu0100890730.git"
14
+ spec.license = "MIT"
15
+
16
+ #Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ #to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "http://rubygems.org"
20
+ #else
21
+ #raise "RubyGems 2.0 or newer is required to protect against "
22
+ # "public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.15"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+
36
+ spec.add_development_dependency "guard"
37
+ spec.add_development_dependency "guard-rspec"
38
+ spec.add_development_dependency "guard-bundler"
39
+
40
+ spec.add_development_dependency "coveralls"
41
+ end