alimento_0100763478 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +12 -0
  4. data/.rspec_status +40 -0
  5. data/.travis.yml +6 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +6 -0
  8. data/Guardfile +82 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +19 -0
  11. data/Rakefile +6 -0
  12. data/alimento.gemspec +44 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/docs/AGrupos.html +368 -0
  16. data/docs/Alimento.html +115 -0
  17. data/docs/Alimentos.html +683 -0
  18. data/docs/Lista.html +635 -0
  19. data/docs/Node.html +398 -0
  20. data/docs/_index.html +143 -0
  21. data/docs/class_list.html +51 -0
  22. data/docs/css/common.css +1 -0
  23. data/docs/css/full_list.css +58 -0
  24. data/docs/css/style.css +492 -0
  25. data/docs/doc/AGrupos.html +368 -0
  26. data/docs/doc/Aliementos.html +105 -0
  27. data/docs/doc/Alimento.html +115 -0
  28. data/docs/doc/Alimentos.html +683 -0
  29. data/docs/doc/Lista.html +635 -0
  30. data/docs/doc/Node.html +398 -0
  31. data/docs/doc/_index.html +148 -0
  32. data/docs/doc/class_list.html +51 -0
  33. data/docs/doc/css/common.css +1 -0
  34. data/docs/doc/css/full_list.css +58 -0
  35. data/docs/doc/css/style.css +492 -0
  36. data/docs/doc/file.README.html +99 -0
  37. data/docs/doc/file_list.html +56 -0
  38. data/docs/doc/frames.html +17 -0
  39. data/docs/doc/index.html +99 -0
  40. data/docs/doc/js/app.js +248 -0
  41. data/docs/doc/js/full_list.js +216 -0
  42. data/docs/doc/js/jquery.js +4 -0
  43. data/docs/doc/method_list.html +219 -0
  44. data/docs/doc/top-level-namespace.html +112 -0
  45. data/docs/file.README.html +99 -0
  46. data/docs/file_list.html +56 -0
  47. data/docs/frames.html +17 -0
  48. data/docs/index.html +99 -0
  49. data/docs/js/app.js +248 -0
  50. data/docs/js/full_list.js +216 -0
  51. data/docs/js/jquery.js +4 -0
  52. data/docs/method_list.html +219 -0
  53. data/docs/top-level-namespace.html +112 -0
  54. data/lib/alimento.rb +10 -0
  55. data/lib/alimento/alimento.rb +93 -0
  56. data/lib/alimento/funcional.rb +32 -0
  57. data/lib/alimento/lista.rb +47 -0
  58. data/lib/alimento/plato.rb +108 -0
  59. data/lib/alimento/version.rb +3 -0
  60. metadata +231 -0
@@ -0,0 +1,10 @@
1
+ require "alimento/version"
2
+ require "alimento/alimento"
3
+ require "alimento/lista"
4
+ require "alimento/funcional"
5
+
6
+
7
+ module Aliementos
8
+ # otro comentario
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,93 @@
1
+ # encoding: utf-8
2
+ # Este módulo se ha creado para describir
3
+ # distintas metodologías de programación
4
+ # haciendo uso del Lenguaje de Programación
5
+ # Ruby.
6
+ # Con ella se han desarrollado los ejemplos
7
+ # de la asignatura Lenguajes y Paradigmas
8
+ # de Programación.
9
+ #
10
+ # Author:: Rossiel D. González
11
+ # Copyright:: Cretive
12
+ # License:: Distributes under the same terms as Ruby
13
+ require "alimento/version"
14
+
15
+
16
+ class Alimentos
17
+
18
+ include Comparable
19
+
20
+ attr_reader :nombre,:proteinas,:glucidos,:lipidos
21
+
22
+ def initialize(nombre,proteinas,glucidos,lipidos)
23
+
24
+ @nombre,@proteinas,@glucidos,@lipidos= nombre,proteinas,glucidos,lipidos
25
+
26
+ end
27
+
28
+ def <=>(other)
29
+ nombre.size <=> other.nombre.size
30
+ ve <=> other.ve
31
+ end
32
+
33
+ def ve
34
+ (@proteinas*4+@glucidos*4+@lipidos*9).round(3)
35
+ end
36
+
37
+
38
+ def aibc(g)
39
+ i = 0
40
+ r = []
41
+ while i < g.size
42
+ index = 1
43
+ s = []
44
+ while index < g[i].size
45
+ if g[i][index] < g[i][0]
46
+ s << 0.0
47
+ else
48
+ s << (((g[i][index] - g[i][0]) + (g[i][index-1] - g[i][0]))/2)*5
49
+ end
50
+ index = index + 1
51
+ end
52
+ r << s
53
+ i = i + 1
54
+ end
55
+ suma = []
56
+ j = 0
57
+ while j < g.size
58
+ k = 0
59
+ s = 0
60
+ while k < r[j].size
61
+ s = s + r[j][k]
62
+ k = k + 1
63
+ end
64
+ suma << s
65
+ j = j + 1
66
+ end
67
+ suma
68
+ end
69
+
70
+ def to_s
71
+
72
+ "Alimento: #{@nombre}\n------------------------------\nProteínas:\s#{@proteinas}g\nGlúcidos:\s#{@glucidos}g\nLípidos:\s#{@lipidos}g"
73
+
74
+ end
75
+
76
+ end
77
+
78
+ class AGrupos < Alimentos
79
+
80
+ attr_reader :ngrupo
81
+
82
+ def initialize(nombre,proteinas,glucidos,lipidos,ngrupo)
83
+ super(nombre,proteinas,glucidos,lipidos)
84
+ @ngrupo = ngrupo
85
+ end
86
+
87
+ def to_s
88
+ s = "Grupo: #{@ngrupo}\n"
89
+ s << super.to_s
90
+ s
91
+ end
92
+
93
+ end
@@ -0,0 +1,32 @@
1
+ def ordenados_for(array)
2
+ list = array.dup
3
+ return list if list.size <= 1 # already sorted
4
+ swapped = true
5
+ while swapped do
6
+ swapped = false
7
+ 0.upto(list.size-2) do |i|
8
+ if (i<list.size-1) && (list[i].ve > list[i+1].ve)
9
+ list[i], list[i+1] = list[i+1], list[i] # swap values
10
+ swapped = true
11
+ end
12
+ end
13
+ end
14
+ list
15
+ end
16
+
17
+ def ordenados_each(array)
18
+ list = array.dup
19
+ # list = copia_ve(array)
20
+ return list if list.size <= 1 # already sorted
21
+ swapped = true
22
+ while swapped do
23
+ swapped = false
24
+ list.each_with_index do |alimento,i|
25
+ if (i<list.size-1) && (list[i].ve > list[i+1].ve)
26
+ list[i], list[i+1] = list[i+1], list[i] # swap values
27
+ swapped = true
28
+ end
29
+ end
30
+ end
31
+ list
32
+ end
@@ -0,0 +1,47 @@
1
+ Node = Struct.new(:value, :next, :prev)
2
+
3
+
4
+ class Lista
5
+
6
+ include Enumerable
7
+
8
+ attr_reader :cabeza,:cola
9
+
10
+ def initialize()
11
+ @cabeza,@cola = nil
12
+ end
13
+
14
+ def each
15
+ aux = @cabeza
16
+ while aux != @cola do
17
+ yield aux.value
18
+ aux = aux.next
19
+ end
20
+ yield aux.value
21
+ end
22
+
23
+ def push(other)
24
+ if @cabeza == nil
25
+ @cabeza = other
26
+ other.next = @cabeza
27
+ other.prev = @cabeza
28
+ @cola = other
29
+ end
30
+
31
+ if @cabeza != nil
32
+ other.next = @cabeza
33
+ other.prev = @cola
34
+ @cola.next = other
35
+ @cabeza.prev = other
36
+ @cola = other
37
+ end
38
+ end
39
+
40
+ def pop_first()
41
+ @cabeza = @cabeza.next
42
+ end
43
+
44
+ def pop_last()
45
+ @cola = @cola.prev
46
+ end
47
+ end
@@ -0,0 +1,108 @@
1
+ class Equivalencia
2
+ attr_accessor :porcion,:equivalencia
3
+
4
+ def initialize(porcion,equivalencia)
5
+ @porcion,@equivalencia = porcion,equivalencia
6
+ end
7
+ end
8
+
9
+ class Plato
10
+ attr_accessor :nombre,:vegetales,:frutas,:granos,:proteinas, :vet
11
+
12
+ TABLA_PORCIONES = [Equivalencia.new('2 piezas pequeñas',20),Equivalencia.new('1 taza',30),Equivalencia.new('1/2 cucharón',50),Equivalencia.new('1 pieza',60)]
13
+ TABLA_ALIMENTOS = [Alimentos.new('Huevo',12.1,0.0,10.5),Alimentos.new('Leche vaca',3.3,4.8,3.2), Alimentos.new('Yogurt',3.8,4.9,3.8), Alimentos.new('Cerdo',21.5,0.0,6.3),Alimentos.new('Ternera',21.1,0.0,3.1),Alimentos.new('Pollo',20.6,0.0,5.6),Alimentos.new('Bacalao',17.7,0.0,0.4),Alimentos.new('Atún',21.5,0.0,15.5),Alimentos.new('Salmón',19.9,0.0,13.6),Alimentos.new('Aceite de oliva',0.0,0.2,99.6),Alimentos.new('Chocolate',5.3,47.0,30.0),Alimentos.new('Azúcar', 0.0,99.8,0.0),Alimentos.new('Arroz',6.8,77.7,0.6),Alimentos.new('Lentejas',23.5,52.0,1.4),Alimentos.new('Papas',2.0,15.4,0.1),Alimentos.new('Tomate', 1.0,3.5,0.2),Alimentos.new('Cebolla',1.3,5.8,0.3),Alimentos.new('Manzana',0.3,12.4,0.4),Alimentos.new('Plátano',1.2,21.4,0.2) ]
14
+ def initialize(name, &block)
15
+ @nombre = name
16
+ @vegetales = []
17
+ @frutas = []
18
+ @granos = []
19
+ @proteinas = []
20
+ @vet = 0
21
+
22
+
23
+ if block_given?
24
+ if block.arity == 1
25
+ yield self
26
+ else
27
+ instance_eval(&block)
28
+ end
29
+ end
30
+ end
31
+ def to_s
32
+ output = @nombre
33
+ output << "\n#{'=' * @nombre.size}\n"
34
+ output << "Composición nutricional: Glúcidos|Lípídos|Proteínas|Valor Energético\n"
35
+ output << "#{@vegetales.join("\n")}\n"
36
+ output << "#{@frutas.join("\n")}\n"
37
+ output << "#{@granos.join("\n")}\n"
38
+ output << "#{@proteinas.join("\n")}\n"
39
+ output << "Valor energético total: #{@vet}\n"
40
+ output
41
+ end
42
+ def vegetal(nombre,options={})
43
+ alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre}
44
+ vegetal = alimento.nombre
45
+ vegetal << ": #{alimento.glucidos}"
46
+ vegetal << "|#{alimento.lipidos}"
47
+ vegetal << "|#{alimento.proteinas}"
48
+ if options[:porcion]
49
+ equivalencia = TABLA_PORCIONES.find{|i| i.porcion == options[:porcion] }.equivalencia
50
+ vegetal << "|#{(alimento.ve*equivalencia).round(3)}"
51
+ @vet =+ alimento.ve*equivalencia
52
+ else
53
+ vegetal << "|#{alimento.ve}"
54
+ @vet =+ alimento.ve
55
+ end
56
+ @vegetales << vegetal
57
+
58
+ end
59
+ def fruta(nombre,options={})
60
+ alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre}
61
+ fruta = alimento.nombre
62
+ fruta = alimento.nombre
63
+ fruta << ": #{alimento.glucidos}"
64
+ fruta << "|#{alimento.lipidos}"
65
+ fruta << "|#{alimento.proteinas}"
66
+ if options[:gramos]
67
+ fruta << "|#{(alimento.ve*options[:gramos]).round(3)}"
68
+ @vet =+ alimento.ve*options[:gramos]
69
+ else
70
+ fruta << "|#{alimento.ve}"
71
+ @vet =+ alimento.ve
72
+ end
73
+ @frutas << fruta
74
+ end
75
+ def grano(nombre,options={})
76
+ alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre}
77
+ grano = alimento.nombre
78
+ grano << ": #{alimento.glucidos}"
79
+ grano << "|#{alimento.lipidos}"
80
+ grano << "|#{alimento.proteinas}"
81
+ if options[:porcion]
82
+ equivalencia = TABLA_PORCIONES.find{|i| i.porcion == options[:porcion] }.equivalencia
83
+ grano << "|#{(alimento.ve*equivalencia).round(3)}"
84
+ @vet =+ alimento.ve*equivalencia
85
+ else
86
+ grano << "|#{alimento.ve}"
87
+ @vet =+ alimento.ve
88
+ end
89
+ @granos << grano
90
+ end
91
+ def proteina(nombre,options={})
92
+ alimento = TABLA_ALIMENTOS.find{|i| i.nombre == nombre}
93
+ proteina = alimento.nombre
94
+ proteina << ": #{alimento.glucidos}"
95
+ proteina << "|#{alimento.lipidos}"
96
+ proteina << "|#{alimento.proteinas}"
97
+ if options[:porcion]
98
+ equivalencia = TABLA_PORCIONES.find{|i| i.porcion == options[:porcion] }.equivalencia
99
+ proteina << "|#{(alimento.ve*equivalencia).round(3)}"
100
+ @vet =+ alimento.ve*equivalencia
101
+ else
102
+ proteina << "|#{alimento.ve}"
103
+ @vet =+ alimento.ve
104
+ end
105
+ @proteinas << proteina
106
+ end
107
+ end
108
+
@@ -0,0 +1,3 @@
1
+ module Alimento
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alimento_0100763478
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rossiel Gonzalez
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: yard
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
+ - !ruby/object:Gem::Dependency
112
+ name: yard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Crear una clase Alimento que contenga los grupos de nutrientes y sus
140
+ cantidades
141
+ email:
142
+ - alu0100763478@ull.edu.es
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".coveralls.yml"
148
+ - ".gitignore"
149
+ - ".rspec_status"
150
+ - ".travis.yml"
151
+ - CODE_OF_CONDUCT.md
152
+ - Gemfile
153
+ - Guardfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - alimento.gemspec
158
+ - bin/console
159
+ - bin/setup
160
+ - docs/AGrupos.html
161
+ - docs/Alimento.html
162
+ - docs/Alimentos.html
163
+ - docs/Lista.html
164
+ - docs/Node.html
165
+ - docs/_index.html
166
+ - docs/class_list.html
167
+ - docs/css/common.css
168
+ - docs/css/full_list.css
169
+ - docs/css/style.css
170
+ - docs/doc/AGrupos.html
171
+ - docs/doc/Aliementos.html
172
+ - docs/doc/Alimento.html
173
+ - docs/doc/Alimentos.html
174
+ - docs/doc/Lista.html
175
+ - docs/doc/Node.html
176
+ - docs/doc/_index.html
177
+ - docs/doc/class_list.html
178
+ - docs/doc/css/common.css
179
+ - docs/doc/css/full_list.css
180
+ - docs/doc/css/style.css
181
+ - docs/doc/file.README.html
182
+ - docs/doc/file_list.html
183
+ - docs/doc/frames.html
184
+ - docs/doc/index.html
185
+ - docs/doc/js/app.js
186
+ - docs/doc/js/full_list.js
187
+ - docs/doc/js/jquery.js
188
+ - docs/doc/method_list.html
189
+ - docs/doc/top-level-namespace.html
190
+ - docs/file.README.html
191
+ - docs/file_list.html
192
+ - docs/frames.html
193
+ - docs/index.html
194
+ - docs/js/app.js
195
+ - docs/js/full_list.js
196
+ - docs/js/jquery.js
197
+ - docs/method_list.html
198
+ - docs/top-level-namespace.html
199
+ - lib/alimento.rb
200
+ - lib/alimento/alimento.rb
201
+ - lib/alimento/funcional.rb
202
+ - lib/alimento/lista.rb
203
+ - lib/alimento/plato.rb
204
+ - lib/alimento/version.rb
205
+ homepage: https://github.com/ULL-ESIT-LPP-1718/tdd-alu0100763478.git
206
+ licenses:
207
+ - MIT
208
+ metadata:
209
+ allowed_push_host: https://rubygems.org
210
+ yard.run: yri
211
+ post_install_message:
212
+ rdoc_options: []
213
+ require_paths:
214
+ - lib
215
+ required_ruby_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ requirements: []
226
+ rubyforge_project:
227
+ rubygems_version: 2.5.1
228
+ signing_key:
229
+ specification_version: 4
230
+ summary: Práctica 06
231
+ test_files: []