nutricion 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,175 @@
1
+
2
+ # Crear un Struct con :value, :next and :prev
3
+ Node = Struct.new(:value, :next, :prev)
4
+
5
+ # Clase Lista.
6
+ class Lista
7
+
8
+ # Se ha incluido el mixin Enumerable.
9
+ include Enumerable
10
+
11
+ #0. METODO INITIALIZE
12
+ def initializate()
13
+ @head = @tail = nil
14
+ end
15
+
16
+ #1. METODO PARA COMPROBAR QUE NO ESTA VACIO
17
+ def empty?()
18
+
19
+ if @head == nil
20
+ return true
21
+ else
22
+ return false
23
+ end
24
+
25
+ end
26
+
27
+
28
+ #2. METODO PARA AÑADIR POR LA CABEZA
29
+ def insert_head(value)
30
+
31
+ node = Node.new(value)
32
+
33
+ if (@head == nil)
34
+ @head = @tail = node
35
+ else
36
+ node.prev = @head
37
+ @head.next = node
38
+ @head = node
39
+ end
40
+
41
+ end
42
+
43
+
44
+ #2. METODO PARA AÑADIR POR LA COLA
45
+ def insert_tail(value)
46
+ node = Node.new(value)
47
+ if (@tail == nil)
48
+ @head = @tail = node
49
+ else
50
+ node.next = @tail
51
+ @tail.prev = node
52
+ @tail = node
53
+ end
54
+
55
+ end
56
+
57
+
58
+ #3. METODO PARA EXTRAER POR LA COLA
59
+ def extract_tail()
60
+
61
+ node = @tail
62
+ @tail = @tail.next
63
+
64
+ if (@tail == nil)
65
+ @head = nil
66
+ else
67
+ @tail.prev = nil
68
+ end
69
+
70
+ node.prev = nil
71
+ node.next =nil
72
+
73
+ return node.value
74
+
75
+ end
76
+
77
+
78
+ #4. METODO PARA EXTRAER POR LA CABEZA
79
+ def extract_head()
80
+
81
+ node = @head
82
+ @head = @head.prev
83
+
84
+ if (@head == nil)
85
+ @tail = nil
86
+ else
87
+ @head.next = nil
88
+ end
89
+
90
+ node.prev = nil
91
+ node.next =nil
92
+
93
+ return node.value
94
+
95
+ end
96
+
97
+ #5. METODO PARA QUE UNA LISTA SEA ENUMERABLE
98
+ def each
99
+
100
+ nodo = @head
101
+
102
+ while(nodo != nil)
103
+ yield nodo.value
104
+ nodo = nodo.prev
105
+ end
106
+
107
+ end
108
+
109
+ #6. MÉTODO PARA ORDENAR UNA LISTA USANDO EL FOR
110
+ def ordenacion_For ()
111
+
112
+ dato = self.map { |x| x}
113
+
114
+ for i in 0..(dato.length) do
115
+ for j in 0..(dato.length-2) do
116
+ if(dato[j] > dato[j+1])
117
+ temporal = dato[j]
118
+ dato[j] = dato[j+1]
119
+ dato[j+1] = temporal
120
+ end
121
+ end
122
+ end
123
+
124
+ dato
125
+
126
+ end
127
+
128
+ #7. MÉTODO PARA ORDENAR UNA LISTA USANDO EL EACH
129
+ def ordenacion_Each ()
130
+
131
+ dato = self.map { |x| x}
132
+
133
+ indice = 0
134
+ dato.each do |x|
135
+ dato.each do |y|
136
+ if (indice < dato.length-1)
137
+ if (dato[indice] > dato[indice+1])
138
+ temporal = dato[indice]
139
+ dato[indice] = dato[indice+1]
140
+ dato[indice+1] = temporal
141
+ end
142
+ end
143
+ indice = indice+1
144
+ end
145
+ indice = 0
146
+ end
147
+ dato
148
+
149
+ end
150
+
151
+ #8. METODO PARA MOSTRAR LOS DATOS POR PANTALLA
152
+ def to_s
153
+
154
+ if (@head != nil)
155
+ nodito = @head
156
+ @salida = nodito.value
157
+
158
+ if ( nodito.prev != nil )
159
+ @salida += ", "
160
+ end
161
+
162
+ while (nodito.prev != nil) do
163
+ nodito = nodito.prev
164
+ @salida += nodito.value
165
+
166
+ if ( nodito.prev != nil )
167
+ @salida += ", "
168
+ end
169
+ end
170
+
171
+ "#{@salida}"
172
+ end
173
+ end
174
+
175
+ end
@@ -0,0 +1,157 @@
1
+ #Clase para crear etiquetas de Información Nutricional
2
+ class Nutricional
3
+
4
+ # Se ha incluido el mixin Comparable.
5
+ include Comparable
6
+
7
+ #Getters
8
+ attr_reader :nombre, :grasas, :saturadas, :monoinsaturadas, :polinsaturadas, :hidratos, :azucares, :polialcoholes, :almidon, :fibra, :proteinas, :vitaminas, :minerales, :sal, :suma_kcal, :suma_kj
9
+
10
+ ########################################################
11
+
12
+ #Constructor de la clase
13
+ def initialize(nombre, saturadas, monoinsaturadas, polinsaturadas, azucares, polialcoholes, almidon, fibra, proteinas, vitaminas, minerales, sal)
14
+
15
+ @nombre = nombre
16
+ @saturadas = saturadas
17
+ @monoinsaturadas = monoinsaturadas
18
+ @polinsaturadas = polinsaturadas
19
+ @azucares = azucares
20
+ @polialcoholes = polialcoholes
21
+ @almidon = almidon
22
+ @fibra = fibra
23
+ @proteinas = proteinas
24
+ @vitaminas = vitaminas
25
+ @minerales = minerales
26
+ @sal = sal
27
+
28
+ grasas_totales()
29
+ hidratos_totales()
30
+
31
+
32
+ kcal_nutricionales_individuales()
33
+ kcal_nutricionales_totales()
34
+
35
+ ir_individual()
36
+
37
+ end
38
+
39
+ ####################################################
40
+
41
+ #Metodo para obtener la suma de grasas (parte opcional)
42
+ def grasas_totales
43
+ @grasas = @saturadas + @monoinsaturadas + @polinsaturadas
44
+ @grasas = @grasas.round(2)
45
+ end
46
+
47
+ #Metodo para obtener la suma de hidratos
48
+ def hidratos_totales
49
+ @hidratos = @azucares + @polialcoholes + @almidon
50
+ @hidratos = @hidratos.round(2)
51
+ end
52
+
53
+ ####################################################
54
+
55
+
56
+ #kcal individuales de cada alimento
57
+ def kcal_nutricionales_individuales()
58
+
59
+ #Kcal de los alimentos
60
+ @kcal_g_saturadas = @saturadas * 9
61
+ @kcal_g_monoinsaturadas = @monoinsaturadas * 9
62
+ @kcal_g_polinsaturadas = @polinsaturadas * 9
63
+ @kcal_azucares = @azucares * 4
64
+ @kcal_polialcoholes = @polialcoholes * 2.4
65
+ @kcal_almidon = @almidon * 4
66
+ @kcal_fibra = @fibra * 2
67
+ @kcal_proteinas = @proteinas * 4
68
+ @kcal_sal = @sal * 6
69
+
70
+
71
+ #Kj de los alimentos
72
+ @kj_g_saturadas = @saturadas * 37
73
+ @kj_g_monoinsaturadas = @monoinsaturadas * 37
74
+ @kj_g_polinsaturadas = @polinsaturadas * 37
75
+ @kj_azucares = @azucares * 17
76
+ @kj_polialcoholes = @polialcoholes * 10
77
+ @kj_almidon = @almidon * 17
78
+ @kj_fibra = @fibra * 8
79
+ @kj_proteinas = @proteinas * 17
80
+ @kj_sal = @sal * 25
81
+
82
+ end
83
+
84
+
85
+ #Suma de todas las kcal y kj individuales de cada alimentos
86
+ def kcal_nutricionales_totales()
87
+
88
+ @suma_kcal = (@kcal_g_saturadas + @kcal_g_monoinsaturadas + @kcal_g_polinsaturadas + @kcal_azucares + @kcal_polialcoholes + @kcal_almidon + @kcal_fibra + @kcal_proteinas + @kcal_sal).round(2)
89
+ @suma_kj = (@kj_g_saturadas + @kj_g_monoinsaturadas + @kj_g_polinsaturadas + @kj_azucares + @kj_polialcoholes + @kj_almidon + @kj_fibra + @kj_proteinas + @kj_sal).round(2)
90
+
91
+ end
92
+
93
+
94
+
95
+ #Calculo del ir individual
96
+ def ir_individual()
97
+ @ir_kj = ( (@suma_kj * 100) / 8400).round(2)
98
+ @ir_kcal = ( (@suma_kcal * 100) / 2000).round(2)
99
+ @ir_grasas = ( (@grasas * 100) / 70).round(2)
100
+ @ir_aci_graso_s = ( (@saturadas * 100) / 20 ).round(2)
101
+ @ir_hidratos = ( (@hidratos * 100) / 260).round(2)
102
+ @ir_azucares = ( (@azucares * 100) / 90).round(2)
103
+ @ir_proteinas = ( (@proteinas * 100) / 50).round(2)
104
+ @ir_sal = ( (@sal * 100) / 6).round(2)
105
+ end
106
+
107
+ #Metodo para permitir que las etiquetas sean comparables
108
+ def <=>(other)
109
+
110
+ return nil unless other.instance_of?Nutricional
111
+ # @nombre <=> other.nombre
112
+ # @saturadas <=> other.saturadas
113
+ # @monoinsaturadas <=> other.monoinsaturadas
114
+ # @polinsaturadas <=> other.polinsaturadas
115
+ # @azucares <=> other.azucares
116
+ # @polialcoholes <=> other.polialcoholes
117
+ # @almidon <=> other.almidon
118
+ # @fibra <=> other.fibra
119
+ # @proteinas <=> other.proteinas
120
+ # @sal <=> other.sal
121
+ # @vitaminas <=> other.vitaminas
122
+ # @minerales <=> other.minerales
123
+ @suma_kcal <=> other.suma_kcal
124
+ end
125
+
126
+ #Metodo para permitir que las etiquetas se puedan sumar
127
+ def +(other)
128
+ return nil unless other.instance_of?Nutricional
129
+ Nutricional.new(nombre + other.nombre,
130
+ saturadas + other.saturadas,
131
+ monoinsaturadas + other.monoinsaturadas,
132
+ polinsaturadas + other.polinsaturadas,
133
+ azucares + other.azucares,
134
+ polialcoholes + other.polialcoholes,
135
+ almidon + other.almidon,
136
+ fibra + other.fibra,
137
+ proteinas + other.proteinas,
138
+ vitaminas + other.vitaminas,
139
+ minerales + other.minerales,
140
+ sal + other.sal)
141
+
142
+ end
143
+
144
+ #Muestreo de la tabla
145
+ def to_s()
146
+ "El alimento analizado es #{@nombre}." +
147
+ "\nValor energético: #{@suma_kcal} kcal (#{@ir_kcal}) / #{@suma_kj} kj (#{@ir_kj})." +
148
+ "\nGrasas: #{@grasas} (#{@ir_grasas}) de las cuales saturadas hay #{@saturadas} gramos (#{@ir_aci_graso_s}), monoinsaturadas hay #{@monoinsaturadas} gramos y de polinsaturadas #{@polinsaturadas} gramos." +
149
+ "\nTenemos de hidratos: #{@hidratos} gramos (#{@ir_hidratos}), de los cuales, azucares hay #{@azucares} gramos (#{@ir_azucares}), polialcoholes hay #{@polialcoholes} gramos y #{@almidon} gramos." +
150
+ "\nTenemos de fibra: #{@fibra} gramos." +
151
+ "\nTenemos de proteinas: #{@proteinas} gramos (#{@ir_proteinas})." +
152
+ "\nTenemos de sal: #{@sal} gramos (#{@ir_sal})." +
153
+ "\nTenemos de vitaminas: #{@vitaminas} gramos y de minerales: #{@minerales} gramos."
154
+ end
155
+
156
+
157
+ end
@@ -0,0 +1,4 @@
1
+ module Nutricion
2
+ #Version actual de la gema
3
+ VERSION = "0.1.0"
4
+ end
data/lib/nutricion.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "nutricion/version"
2
+ require "nutricion/nutricion_code"
3
+ require "nutricion/lista_code"
4
+ require "nutricion/icc"
5
+ require "nutricion/array"
6
+ require "nutricion/dsl"
7
+
8
+ #Modulo de la gema Nutricion
9
+ module Nutricion
10
+ # Your code goes here...
11
+ end
data/nutricion.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nutricion/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nutricion"
8
+ spec.version = Nutricion::VERSION
9
+ spec.authors = ["Iván Borges"]
10
+ spec.email = ["alu0100880755@ull.edu.es"]
11
+
12
+ spec.summary = %q{"Esta es una gema para calcular información esencial sobre los alimentos"}
13
+ spec.description = %q{"Esta es una gema para calcular información esencial sobre los alimentos (kcal, grasas, proteinas, azucares...)"}
14
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1819/tdd-alu0100880755.git"
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"] = "https://github.com/ULL-ESIT-LPP-1819/tdd-alu0100880755.git"
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
+ spec.add_development_dependency "coveralls"
40
+ end
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nutricion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Iván Borges
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-11 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: '"Esta es una gema para calcular información esencial sobre los alimentos
112
+ (kcal, grasas, proteinas, azucares...)"'
113
+ email:
114
+ - alu0100880755@ull.edu.es
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".coveralls.yml"
120
+ - ".gitignore"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - Guardfile
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - doc/Individuo.html
129
+ - doc/Lista.html
130
+ - doc/Node.html
131
+ - doc/Nutricion.html
132
+ - doc/Nutricional.html
133
+ - doc/Paciente.html
134
+ - doc/_index.html
135
+ - doc/class_list.html
136
+ - doc/css/common.css
137
+ - doc/css/full_list.css
138
+ - doc/css/style.css
139
+ - doc/file.README.html
140
+ - doc/file_list.html
141
+ - doc/frames.html
142
+ - doc/index.html
143
+ - doc/js/app.js
144
+ - doc/js/full_list.js
145
+ - doc/js/jquery.js
146
+ - doc/method_list.html
147
+ - doc/top-level-namespace.html
148
+ - lib/nutricion.rb
149
+ - lib/nutricion/array.rb
150
+ - lib/nutricion/dsl.rb
151
+ - lib/nutricion/icc.rb
152
+ - lib/nutricion/lista_code.rb
153
+ - lib/nutricion/nutricion_code.rb
154
+ - lib/nutricion/version.rb
155
+ - nutricion.gemspec
156
+ homepage: https://github.com/ULL-ESIT-LPP-1819/tdd-alu0100880755.git
157
+ licenses: []
158
+ metadata: {}
159
+ post_install_message:
160
+ rdoc_options: []
161
+ require_paths:
162
+ - lib
163
+ required_ruby_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ requirements: []
174
+ rubyforge_project:
175
+ rubygems_version: 2.6.11
176
+ signing_key:
177
+ specification_version: 4
178
+ summary: '"Esta es una gema para calcular información esencial sobre los alimentos"'
179
+ test_files: []