alimento0101069937 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Guardfile +82 -0
- data/README.md +77 -0
- data/Rakefile +17 -0
- data/alimento.gemspec +38 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimento.html +152 -0
- data/docs/Alimento/Alimento.html +931 -0
- data/docs/Alimento/Carbohidratos.html +158 -0
- data/docs/Alimento/Carnes.html +158 -0
- data/docs/Alimento/Frutas.html +158 -0
- data/docs/Alimento/Grasos.html +158 -0
- data/docs/Alimento/Lacteos.html +158 -0
- data/docs/Alimento/List.html +723 -0
- data/docs/Alimento/List/Node.html +409 -0
- data/docs/Alimento/Pescados.html +158 -0
- data/docs/Alimento/Verduras.html +158 -0
- data/docs/_index.html +236 -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 +139 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +139 -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 +219 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/alimento.rb +6 -0
- data/lib/alimento/fuente.rb +248 -0
- data/lib/alimento/version.rb +3 -0
- metadata +181 -0
data/lib/alimento.rb
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Módulo creado para describir y representar
|
3
|
+
# alimentos haciendo uso del Lenguaje de
|
4
|
+
# Programación Ruby.
|
5
|
+
# En él se han desarrollado las prácticas #6, #7 y #8
|
6
|
+
# de la asignatura Lenguajes y Paradigmas de Programación.
|
7
|
+
#
|
8
|
+
# Author:: Santiago Padilla (mailto:S.Padilla@x.y)
|
9
|
+
# Copyright:: Cretive Commons
|
10
|
+
# License:: Distributes under the same terms as Ruby
|
11
|
+
|
12
|
+
module Alimento
|
13
|
+
|
14
|
+
# Esta clase permite representar un alimento con sus
|
15
|
+
# nutrientes, así como calcular sus calorías. Todo ello
|
16
|
+
# en función de la cantidad de alimento que
|
17
|
+
# especifiquemos (por defecto: 100gr)
|
18
|
+
# Se ha incluido el mixin Comparable, que permite comparar
|
19
|
+
# los alimentos en función de su aporte calórico
|
20
|
+
class Alimento
|
21
|
+
attr_reader :nombre, :proteinas,:glucidos, :lipidos
|
22
|
+
include Comparable
|
23
|
+
|
24
|
+
# Método necesario para usar 'Comparable'
|
25
|
+
def <=> otroAlimento
|
26
|
+
self.calorias <=> otroAlimento.calorias
|
27
|
+
end
|
28
|
+
|
29
|
+
# Se asignan el nombre y los nutrientes del alimento
|
30
|
+
def initialize(nombre,proteinas,glucidos,lipidos)
|
31
|
+
@nombre= nombre
|
32
|
+
@proteinas= proteinas
|
33
|
+
@glucidos= glucidos
|
34
|
+
@lipidos= lipidos
|
35
|
+
end
|
36
|
+
|
37
|
+
# Da formato a la presentación del alimento
|
38
|
+
def to_s
|
39
|
+
"#{nombre}(Pr_#{proteinas}; Glc_#{glucidos}; Lip_#{lipidos}; Cal_#{self.calorias})"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Calcula las calorías del alimento según sus nutrientes
|
43
|
+
def calorias
|
44
|
+
((proteinas+glucidos)*4 + lipidos*9).round(1)
|
45
|
+
end
|
46
|
+
end #clase
|
47
|
+
|
48
|
+
# Esta clase permite crear listas doblemente enlazadas.
|
49
|
+
# El objetivo es que cada lista represente un grupo de
|
50
|
+
# alimentos y cada alimento, un nodo de la lista.
|
51
|
+
# Se incluye el mixin Enumerable para poder usar métodos
|
52
|
+
# de dicho módulo
|
53
|
+
class List
|
54
|
+
# Estructura de nodo dentro de la lista.
|
55
|
+
Node = Struct.new(:valor, :prev, :sigte)
|
56
|
+
# "Apuntadores": cola y cabeza de la lista.
|
57
|
+
attr_reader :head, :tail
|
58
|
+
include Enumerable
|
59
|
+
|
60
|
+
# Método necesario para usar 'Enumerable'
|
61
|
+
def each
|
62
|
+
puntero=@tail
|
63
|
+
while puntero != @head
|
64
|
+
yield puntero.valor
|
65
|
+
puntero=puntero.sigte
|
66
|
+
end
|
67
|
+
yield puntero.valor
|
68
|
+
end
|
69
|
+
|
70
|
+
# Establece valores por defecto de la cola y
|
71
|
+
# cabeza de la lista
|
72
|
+
def initialize
|
73
|
+
@head= nil #cabeza de lista
|
74
|
+
@tail= nil #cola de lista
|
75
|
+
end
|
76
|
+
|
77
|
+
# Inserta uno ó varios nodos a la lista. Se introducen
|
78
|
+
# tantos nodos a la listacomo argumentos le pasamos
|
79
|
+
# al método.
|
80
|
+
def insertaNodo(*arg)
|
81
|
+
i=0
|
82
|
+
while i< arg.size
|
83
|
+
nodo=Node.new(arg[i])
|
84
|
+
if @head== nil
|
85
|
+
@head= nodo
|
86
|
+
@tail= nodo
|
87
|
+
else
|
88
|
+
nodo.prev= @head
|
89
|
+
@head.sigte= nodo
|
90
|
+
@head= nodo
|
91
|
+
end
|
92
|
+
i=i+1
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# Remove-Head: Elimina el nodo-cabeza de la lista
|
97
|
+
def rmHead
|
98
|
+
if @head.prev!=nil
|
99
|
+
@head=@head.prev
|
100
|
+
@head.sigte=nil
|
101
|
+
elsif @head.valor!=nil
|
102
|
+
@tail=@head=nil
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Remove Tail: Elimina el nodo-cola de la lista
|
107
|
+
def rmTail
|
108
|
+
if @tail.sigte!=nil
|
109
|
+
@tail=@tail.sigte
|
110
|
+
@tail.prev=nil
|
111
|
+
elsif @tail.valor!=nil
|
112
|
+
@head=@tail=nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
# Presenta los alimentos de la lista en un array
|
117
|
+
def table
|
118
|
+
self.map{|i| [i.nombre, i.proteinas, i.glucidos, i.lipidos, i.calorias]}
|
119
|
+
end
|
120
|
+
|
121
|
+
# Ordena los alimentos por calorías mediante
|
122
|
+
# bucle 'FOR'
|
123
|
+
def to_for
|
124
|
+
v=self.table
|
125
|
+
ordenado = false
|
126
|
+
until ordenado
|
127
|
+
ordenado = true
|
128
|
+
for i in 0..(v.length - 2)
|
129
|
+
if v[i][4] > v[i + 1][4]
|
130
|
+
ordenado = false
|
131
|
+
v[i], v[i + 1] = v[i + 1], v[i]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
return v
|
136
|
+
end
|
137
|
+
|
138
|
+
# Inserta alimentos ordenadados(calorías) en un vector
|
139
|
+
# de forma recursiva
|
140
|
+
def inserta(v,d,index=v.size-1)#VectorResultado, Nodo
|
141
|
+
return v<< d if v[index]==nil #caso vector vacío
|
142
|
+
return v.insert(index+1,d) if d[4]>= v[index][4] || index< 0
|
143
|
+
inserta(v,d,index-1)
|
144
|
+
end
|
145
|
+
|
146
|
+
# Método 'each' que obtiene una tabla ordenada de alimentos
|
147
|
+
# ordenados por calorías
|
148
|
+
def to_each
|
149
|
+
vector=[]
|
150
|
+
self.table.each{|item| inserta(vector,item)}
|
151
|
+
vector
|
152
|
+
end
|
153
|
+
|
154
|
+
# Método 'sort' que obtiene una tabla ordenada de alimentos
|
155
|
+
# ordenados por calorías
|
156
|
+
def to_sort
|
157
|
+
self.table.sort_by{|i| i[4]}
|
158
|
+
end
|
159
|
+
|
160
|
+
private :inserta
|
161
|
+
end #clase
|
162
|
+
|
163
|
+
|
164
|
+
# Clase que representa al grupo de alimentos: Group
|
165
|
+
# Hereda de la clase Alimento e incluye el atributo: grupo
|
166
|
+
class Group < Alimento
|
167
|
+
attr_reader :grupo
|
168
|
+
|
169
|
+
def initialize(a,b,c,d,e)
|
170
|
+
super(b,c,d,e)
|
171
|
+
@grupo= a
|
172
|
+
end
|
173
|
+
end
|
174
|
+
# Clase que presenta nutrientes y calorías de un plato
|
175
|
+
class Plato
|
176
|
+
|
177
|
+
def initialize (name, &block)
|
178
|
+
@name = name
|
179
|
+
@ingredients = []
|
180
|
+
@listaEntorno= eval('@lista',block.binding)
|
181
|
+
instance_eval(&block)
|
182
|
+
end
|
183
|
+
|
184
|
+
# Método para presentar en tabla los nutrientes del plato
|
185
|
+
def to_s
|
186
|
+
output = @name
|
187
|
+
caloriasTotal=0
|
188
|
+
output << "\n#{'=' * @name.size}\n"
|
189
|
+
output << "Composición nutricional:\n"
|
190
|
+
output << "\t\tglúcidos\tproteínas\tlípidos\t\tcalorías\n"
|
191
|
+
@ingredients.map do |i|
|
192
|
+
output<< "#{i[0].nombre}\t\t#{(i[0].glucidos*i[1]).round(3)}"
|
193
|
+
output<< "\t\t#{(i[0].proteinas*i[1]).round(3)}"
|
194
|
+
output<< "\t\t#{(i[0].lipidos*i[1]).round(3)}"
|
195
|
+
output<< "\t\t#{(i[0].calorias*i[1]).round(2)}\n"
|
196
|
+
caloriasTotal+= (i[0].calorias*i[1])
|
197
|
+
end
|
198
|
+
output << "Valor energético total:\t\t\t\t\t\t"
|
199
|
+
output << "#{caloriasTotal.round(2)}"
|
200
|
+
output
|
201
|
+
end
|
202
|
+
|
203
|
+
# Método para extraer medidas del alimento en gramos
|
204
|
+
def medidas (medida,name,muestra)
|
205
|
+
@ali=@listaEntorno.find{|i| i.nombre==name}
|
206
|
+
if muestra[:porcion]
|
207
|
+
gramos= medida * eval(muestra[:porcion].split(/ /)[0]<< '.to_f')
|
208
|
+
else
|
209
|
+
gramos= muestra[:gramos]
|
210
|
+
end
|
211
|
+
gramos=gramos/100
|
212
|
+
@ingredients << ([@ali] << gramos)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Método de vegetales
|
216
|
+
def vegetal(name, muestra)
|
217
|
+
#pieza peq~ 90gr
|
218
|
+
self.medidas(90,name,muestra)
|
219
|
+
end
|
220
|
+
|
221
|
+
# Método de frutas
|
222
|
+
def fruta(name, muestra)
|
223
|
+
#pieza~ 160gr
|
224
|
+
self.medidas(160,name,muestra)
|
225
|
+
end
|
226
|
+
|
227
|
+
# Método de cereales
|
228
|
+
def cereal(name, muestra)
|
229
|
+
#Una taza~ 90gr
|
230
|
+
self.medidas(90,name,muestra)
|
231
|
+
end
|
232
|
+
|
233
|
+
# Método de proteínas
|
234
|
+
def proteina(name, muestra)
|
235
|
+
#pieza~ 70gr
|
236
|
+
self.medidas(70,name,muestra)
|
237
|
+
end
|
238
|
+
|
239
|
+
# Método de aceites
|
240
|
+
def aceite(name, muestra)
|
241
|
+
#Una cucharada~ 15gr
|
242
|
+
self.medidas(15,name,muestra)
|
243
|
+
end
|
244
|
+
|
245
|
+
end#class
|
246
|
+
|
247
|
+
end #module
|
248
|
+
|
metadata
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alimento0101069937
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- alu0101069937
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- alu0101069937@ull.edu.es
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".coveralls.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Guardfile
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- alimento.gemspec
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- docs/Alimento.html
|
130
|
+
- docs/Alimento/Alimento.html
|
131
|
+
- docs/Alimento/Carbohidratos.html
|
132
|
+
- docs/Alimento/Carnes.html
|
133
|
+
- docs/Alimento/Frutas.html
|
134
|
+
- docs/Alimento/Grasos.html
|
135
|
+
- docs/Alimento/Lacteos.html
|
136
|
+
- docs/Alimento/List.html
|
137
|
+
- docs/Alimento/List/Node.html
|
138
|
+
- docs/Alimento/Pescados.html
|
139
|
+
- docs/Alimento/Verduras.html
|
140
|
+
- docs/_index.html
|
141
|
+
- docs/class_list.html
|
142
|
+
- docs/css/common.css
|
143
|
+
- docs/css/full_list.css
|
144
|
+
- docs/css/style.css
|
145
|
+
- docs/file.README.html
|
146
|
+
- docs/file_list.html
|
147
|
+
- docs/frames.html
|
148
|
+
- docs/index.html
|
149
|
+
- docs/js/app.js
|
150
|
+
- docs/js/full_list.js
|
151
|
+
- docs/js/jquery.js
|
152
|
+
- docs/method_list.html
|
153
|
+
- docs/top-level-namespace.html
|
154
|
+
- lib/alimento.rb
|
155
|
+
- lib/alimento/fuente.rb
|
156
|
+
- lib/alimento/version.rb
|
157
|
+
homepage: https://github.com/ULL-ESIT-LPP-1718/tdd-alu0101069937.git
|
158
|
+
licenses: []
|
159
|
+
metadata:
|
160
|
+
allowed_push_host: https://rubygems.org
|
161
|
+
post_install_message:
|
162
|
+
rdoc_options: []
|
163
|
+
require_paths:
|
164
|
+
- lib
|
165
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
requirements: []
|
176
|
+
rubyforge_project:
|
177
|
+
rubygems_version: 2.7.2
|
178
|
+
signing_key:
|
179
|
+
specification_version: 4
|
180
|
+
summary: Calculo de nutrientes de un alimento
|
181
|
+
test_files: []
|