alimentacion 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/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +95 -0
- data/Guardfile +82 -0
- data/README.md +9 -0
- data/Rakefile +6 -0
- data/alimentacion.gemspec +38 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimentacion.html +110 -0
- data/docs/Alimentacion/Error.html +103 -0
- data/docs/Alimentos.html +529 -0
- data/docs/Eficiencia_Energetica.html +484 -0
- data/docs/Gemfile.html +98 -0
- data/docs/Gemfile_lock.html +177 -0
- data/docs/Guardfile.html +165 -0
- data/docs/Lista.html +622 -0
- data/docs/Object.html +127 -0
- data/docs/Plato.html +504 -0
- data/docs/README_md.html +104 -0
- data/docs/Rakefile.html +100 -0
- data/docs/alimentacion_gemspec.html +132 -0
- data/docs/bin/setup.html +100 -0
- data/docs/created.rid +16 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +590 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +117 -0
- data/docs/js/darkfish.js +161 -0
- data/docs/js/jquery.js +4 -0
- data/docs/js/navigation.js +141 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +109 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +293 -0
- data/lib/alimentacion.rb +11 -0
- data/lib/alimentacion/alimentos.rb +65 -0
- data/lib/alimentacion/lista.rb +136 -0
- data/lib/alimentacion/menu_dsl.rb +36 -0
- data/lib/alimentacion/plato_dsl.rb +45 -0
- data/lib/alimentacion/platos.rb +199 -0
- data/lib/alimentacion/version.rb +3 -0
- metadata +221 -0
data/lib/alimentacion.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "alimentacion/version"
|
2
|
+
require "alimentacion/alimentos"
|
3
|
+
require "alimentacion/lista"
|
4
|
+
require "alimentacion/platos"
|
5
|
+
require "alimentacion/plato_dsl"
|
6
|
+
require "alimentacion/menu_dsl"
|
7
|
+
|
8
|
+
module Alimentacion
|
9
|
+
class Error < StandardError; end
|
10
|
+
# Your code goes here...
|
11
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Esta clase contiene información sobre alimentos, tales como las proteínas, lípidos, hidratos,etc.
|
3
|
+
# Se calcula el valor energético de cada alimento, así como su impacto ambiental en hombres y mujeres.
|
4
|
+
#
|
5
|
+
# Author:: David Hernández Suárez (mailto:david@alimentos)
|
6
|
+
# Copyright:: Cretive Commons
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
|
9
|
+
class Alimentos
|
10
|
+
attr_accessor :nombre,:proteinas,:hidratos,:lipidos,:gei,:terreno
|
11
|
+
include Comparable
|
12
|
+
|
13
|
+
# Se utiliza el módulo Comparable, comparando los alimentos en base a sus proteínas.
|
14
|
+
def <=>(anOther)
|
15
|
+
self. proteinas <=> anOther.proteinas
|
16
|
+
end
|
17
|
+
|
18
|
+
# Se asignan el nombre del alimento, sus proteínas, hidratos, lípidos, gases y uso del terreno.
|
19
|
+
def initialize(nombre,proteinas,hidratos,lipidos,gei,terreno)
|
20
|
+
@nombre,@proteinas,@hidratos,@lipidos,@gei,@terreno = nombre,proteinas,hidratos,lipidos,gei,terreno
|
21
|
+
end
|
22
|
+
|
23
|
+
# Se obtiene el alimento formateado.
|
24
|
+
def to_s
|
25
|
+
"(#{@nombre},#{@proteinas},#{@hidratos},#{@lipidos},#{@gei},#{@terreno})"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Se calcula el valor energético (calórico) del alimento.
|
29
|
+
def valor_energetico
|
30
|
+
energia = 4 * (@proteinas + @hidratos) + (@lipidos * 9)
|
31
|
+
energia.round(2)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Función auxiliar para calcular los gases anuales.
|
35
|
+
def auxiliar(gramos)
|
36
|
+
x = ( @gei * gramos ) / 1000
|
37
|
+
end
|
38
|
+
|
39
|
+
# Función auxiliar para calcular el uso del terreno anual.
|
40
|
+
def auxiliar2(gramos)
|
41
|
+
x = ( @terreno * gramos ) / 1000
|
42
|
+
end
|
43
|
+
|
44
|
+
# Se calcula el impacto ambiental de un alimento en un hombre.
|
45
|
+
def impacto_hombre(gramos)
|
46
|
+
alimento1 = Alimentos.new("Carne vaca",21.1,0.0,3.1,50.0,164.0)
|
47
|
+
alimento2 = Alimentos.new("Salmon",19.9,0.0,13.6,6.0,3.7)
|
48
|
+
alimento3 = Alimentos.new("Huevos",13.0,1.1,11.0,4.2,5.7)
|
49
|
+
a = alimento1.auxiliar(gramos) + alimento2.auxiliar(gramos) + alimento3.auxiliar(gramos)
|
50
|
+
b = alimento1.auxiliar2(gramos) + alimento2.auxiliar2(gramos) + alimento3.auxiliar2(gramos)
|
51
|
+
vector = [a.round(2),b.round(2)]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Se calcula el impacto ambiental de un alimento en una mujer.
|
55
|
+
def impacto_mujer(gramos1,gramos2,gramos3,gramos4,gramos5)
|
56
|
+
alimento1 = Alimentos.new("Tofu",10,2.37,6,2.0,2.2)
|
57
|
+
alimento2 = Alimentos.new("Nuez",50,10.5,27,0.3,7.9)
|
58
|
+
alimento3 = Alimentos.new("Camarones",10,0.85,0.34,18.0,2.0)
|
59
|
+
alimento4 = Alimentos.new("Chocolate",5,44.34,28.30,2.3,3.4)
|
60
|
+
alimento5 = Alimentos.new("Leche",6,8.72,5.82,3.2,8.9)
|
61
|
+
a = alimento1.auxiliar(gramos1) + alimento2.auxiliar(gramos2) + alimento3.auxiliar(gramos3) + alimento4.auxiliar(gramos4) + alimento5.auxiliar(gramos5)
|
62
|
+
b = alimento1.auxiliar2(gramos1) + alimento2.auxiliar2(gramos2) + alimento3.auxiliar2(gramos3) + alimento4.auxiliar2(gramos4) + alimento5.auxiliar2(gramos5)
|
63
|
+
vector = [a.round(2),b.round(2)]
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Esta clase implementa una lista doblemente enlazada.
|
3
|
+
# Se desarrollan los métodos para insertar y extraer nodos por la cabeza y por la cola, e imprimir la lista completa.
|
4
|
+
# Se utiliza una estructura para representar los nodos, con los valores value, next y prev.
|
5
|
+
#
|
6
|
+
# Author:: David Hernández Suárez (mailto:david@alimentos)
|
7
|
+
# Copyright:: Cretive Commons
|
8
|
+
# License:: Distributes under the same terms as Ruby
|
9
|
+
|
10
|
+
Nodo = Struct.new(:value, :next, :prev)
|
11
|
+
class Lista
|
12
|
+
include Enumerable
|
13
|
+
|
14
|
+
# Se utiliza el módulo Enumerable, para enumerar cualquier lista enlazada.
|
15
|
+
def each
|
16
|
+
aux = @head
|
17
|
+
while !aux.nil?
|
18
|
+
yield aux[:value]
|
19
|
+
aux = aux[:next]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_accessor :head,:tail
|
24
|
+
|
25
|
+
# Se asignan la cabecera de la lista y la cola de la lista. Inicialmente apuntan a nil.
|
26
|
+
def initialize(head,tail)
|
27
|
+
@head = nil
|
28
|
+
@tail = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
# Se inserta un nodo por la cabeza de la lista
|
32
|
+
def insert_head(value)
|
33
|
+
if @head.nil?
|
34
|
+
@head = Nodo.new(value, nil, nil)
|
35
|
+
@tail = @head
|
36
|
+
else
|
37
|
+
@head[:prev] = Nodo.new(value, @head, nil)
|
38
|
+
@head = @head[:prev]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Se inserta un nodo por la cola de la lista
|
43
|
+
def insert_tail(value)
|
44
|
+
if @head.nil?
|
45
|
+
@head = Nodo.new(value, nil, nil)
|
46
|
+
@tail = @head
|
47
|
+
else
|
48
|
+
@tail[:next] = Nodo.new(value, nil, @tail)
|
49
|
+
@tail = @tail[:next]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Se extrae el nodo situado en la cabeza de la lista
|
54
|
+
def extract_head()
|
55
|
+
if @head.nil?
|
56
|
+
raise RuntimeError, "La lista está vacía"
|
57
|
+
else
|
58
|
+
if @head == @tail
|
59
|
+
@head, @tail = nil
|
60
|
+
else
|
61
|
+
@head = @head[:next]
|
62
|
+
@head[:prev] = nil
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Se extrae el nodo situado en la cola de la lista
|
69
|
+
def extract_tail()
|
70
|
+
if @head.nil?
|
71
|
+
raise RuntimeError, "La lista está vacía"
|
72
|
+
else
|
73
|
+
if @head == @tail
|
74
|
+
@head, @tail = nil
|
75
|
+
else
|
76
|
+
@tail = @tail[:prev]
|
77
|
+
@tail[:next] = nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Se insertan por la cola un conjunto de nodos
|
83
|
+
def insert(nodos)
|
84
|
+
for i in (0.. nodos.size-1)
|
85
|
+
insert_tail(nodos[i])
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Se visualiza la lista
|
90
|
+
def imprimir
|
91
|
+
aux = @head
|
92
|
+
lista = []
|
93
|
+
while (!aux.nil?)
|
94
|
+
lista << aux[:value].to_s
|
95
|
+
aux = aux[:next]
|
96
|
+
end
|
97
|
+
return lista
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
# Calcula el total de gases anuales que tiene la lista de alimentos
|
102
|
+
def dieta_gases_anuales(gramos)
|
103
|
+
aux = @head
|
104
|
+
suma_gases = 0
|
105
|
+
i = 0
|
106
|
+
while (!aux.nil?)
|
107
|
+
suma_gases += aux[:value].auxiliar(gramos[i])
|
108
|
+
aux = aux[:next]
|
109
|
+
i = i+1
|
110
|
+
end
|
111
|
+
return suma_gases.round(2)
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
# Calcula el total de gases diarios que tiene la lista de alimentos
|
116
|
+
def dieta_gases_diarios(gramos)
|
117
|
+
gases_diarios = dieta_gases_anuales(gramos)/365
|
118
|
+
return gases_diarios.round(3)
|
119
|
+
end
|
120
|
+
|
121
|
+
# Calcula el total de uso del terreno que tiene la lista de alimentos
|
122
|
+
def dieta_terreno(gramos)
|
123
|
+
|
124
|
+
aux = @head
|
125
|
+
suma_terreno = 0
|
126
|
+
i = 0
|
127
|
+
while (!aux.nil?)
|
128
|
+
suma_terreno += aux[:value].auxiliar2(gramos[i])
|
129
|
+
aux = aux[:next]
|
130
|
+
i = i+1
|
131
|
+
end
|
132
|
+
return suma_terreno.round(2)
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Menu_DSL
|
2
|
+
attr_reader :nombre_menu, :lista_platos, :precio_menu
|
3
|
+
|
4
|
+
def initialize (nombre_menu, &block)
|
5
|
+
#@nombre_menu = nombre_menu
|
6
|
+
@lista_platos = []
|
7
|
+
@precio_menu = 0
|
8
|
+
|
9
|
+
if block_given?
|
10
|
+
if block.arity == 1
|
11
|
+
yield self
|
12
|
+
else
|
13
|
+
instance_eval(&block)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def descripcion(n)
|
19
|
+
@nombre_menu = n
|
20
|
+
end
|
21
|
+
|
22
|
+
def componente(descripcion, precio = {})
|
23
|
+
componente = "\n - " + descripcion
|
24
|
+
componente << " || Precio: #{precio[:Precio]} € " if precio[:Precio]
|
25
|
+
@precio_menu += precio[:Precio]
|
26
|
+
@lista_platos << componente
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
output = @nombre_menu
|
31
|
+
output << "\n#{'=' * @nombre_menu.size}\n\n"
|
32
|
+
output << "Platos: \n #{@lista_platos.join(' ')}\n\n"
|
33
|
+
output << "Precio total: #{@precio_menu} €"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class Plato_DSL
|
2
|
+
|
3
|
+
attr_reader :nombre_plato, :lista_alimentos
|
4
|
+
include Comparable
|
5
|
+
def <=>(anOther)
|
6
|
+
self.porcentaje_proteinas <=> anOther.porcentaje_proteinas
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(nombre_plato, &block)
|
10
|
+
#@nombre_plato = nombre_plato
|
11
|
+
@lista_alimentos = []
|
12
|
+
|
13
|
+
if block_given?
|
14
|
+
if block.arity == 1
|
15
|
+
yield self
|
16
|
+
else
|
17
|
+
instance_eval(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def nombre (n)
|
23
|
+
@nombre_plato = n
|
24
|
+
end
|
25
|
+
|
26
|
+
def alimento(descripcion, gramos = {})
|
27
|
+
alimento = "\n - " + descripcion
|
28
|
+
alimento << "\n Información nutricional:"
|
29
|
+
alimento << " || Cantidad: #{gramos[:Gramos]} gramos ||" if gramos[:Gramos]
|
30
|
+
alimento << " Proteínas: #{gramos[:Proteinas]} gramos ||" if gramos[:Proteinas]
|
31
|
+
alimento << " Hidratos: #{gramos[:Hidratos]} gramos ||" if gramos[:Hidratos]
|
32
|
+
alimento << " Lípidos: #{gramos[:Lipidos]} gramos" if gramos[:Lipidos]
|
33
|
+
alimento << "\n Información ambiental:"
|
34
|
+
alimento << " Gases anuales: #{gramos[:Gases]} kilogramos ||" if gramos[:Gases]
|
35
|
+
alimento << " Uso del terreno: #{gramos[:Terreno]} metros cuadrados" if gramos[:Gases]
|
36
|
+
@lista_alimentos << alimento
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
output = @nombre_plato
|
41
|
+
output << "\n#{'=' * @nombre_plato.size}\n\n"
|
42
|
+
output << "Alimentos: \n #{@lista_alimentos.join(' ')}\n\n"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,199 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Esta clase contiene información acerca de los distintos alimentos que forman un plato.
|
3
|
+
# Se calcula el porcentaje de proteínas, hidratos y lípidos que contiene cada conjunto de alimentos, así como su valor energético.
|
4
|
+
#
|
5
|
+
# Author:: David Hernández Suárez (mailto:alu0101048239@ull.edu.es)
|
6
|
+
# Copyright:: Cretive Commons
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
|
9
|
+
class Plato
|
10
|
+
attr_reader :nombre_plato, :lista_alimentos, :lista_gramos
|
11
|
+
include Comparable
|
12
|
+
|
13
|
+
# Se utiliza el módulo Comparable, comparando los alimentos en base a su porcentaje de proteínas.
|
14
|
+
def <=>(anOther)
|
15
|
+
self.porcentaje_proteinas <=> anOther.porcentaje_proteinas
|
16
|
+
end
|
17
|
+
|
18
|
+
# Se asignan el nombre del plato, la lista de alimentos que lo compone y los gramos de cada alimento.
|
19
|
+
def initialize(nombre_plato, lista_alimentos, lista_gramos)
|
20
|
+
@nombre_plato = nombre_plato
|
21
|
+
@lista_alimentos = lista_alimentos
|
22
|
+
@lista_gramos = lista_gramos
|
23
|
+
end
|
24
|
+
|
25
|
+
# Se calcula el porcentaje de proteínas total del plato
|
26
|
+
def porcentaje_proteinas
|
27
|
+
aux = @lista_alimentos.head
|
28
|
+
aux2 = @lista_gramos.head
|
29
|
+
suma_proteinas = 0
|
30
|
+
suma_gramos = 0
|
31
|
+
while (!aux.nil?)
|
32
|
+
suma_proteinas += ( (aux[:value].proteinas)*(aux2[:value]) )/100
|
33
|
+
suma_gramos += aux2[:value]
|
34
|
+
aux = aux[:next]
|
35
|
+
aux2 = aux2[:next]
|
36
|
+
end
|
37
|
+
|
38
|
+
return ( (suma_proteinas/suma_gramos)*100 ).round(2)
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
# Se calcula el porcentaje de hidratos de carbono total del plato
|
43
|
+
def porcentaje_hidratos
|
44
|
+
aux = @lista_alimentos.head
|
45
|
+
aux2 = @lista_gramos.head
|
46
|
+
suma_hidratos = 0
|
47
|
+
suma_gramos = 0
|
48
|
+
while (!aux.nil?)
|
49
|
+
suma_hidratos += ( (aux[:value].hidratos)*(aux2[:value]) )/100
|
50
|
+
suma_gramos += aux2[:value]
|
51
|
+
aux = aux[:next]
|
52
|
+
aux2 = aux2[:next]
|
53
|
+
end
|
54
|
+
|
55
|
+
return ( (suma_hidratos/suma_gramos)*100 ).round(2)
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# Se calcula el porcentaje de lípidos total del plato
|
60
|
+
def porcentaje_lipidos
|
61
|
+
aux = @lista_alimentos.head
|
62
|
+
aux2 = @lista_gramos.head
|
63
|
+
suma_lipidos = 0
|
64
|
+
suma_gramos = 0
|
65
|
+
while (!aux.nil?)
|
66
|
+
suma_lipidos += ( (aux[:value].lipidos)*(aux2[:value]) )/100
|
67
|
+
suma_gramos += aux2[:value]
|
68
|
+
aux = aux[:next]
|
69
|
+
aux2 = aux2[:next]
|
70
|
+
end
|
71
|
+
|
72
|
+
return ( (suma_lipidos/suma_gramos)*100 ).round(2)
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
# Se calcula el valor calórico total del plato
|
77
|
+
def valor_calorico
|
78
|
+
aux = @lista_alimentos.head
|
79
|
+
aux2 = @lista_gramos.head
|
80
|
+
calorias = 0
|
81
|
+
while (!aux.nil?)
|
82
|
+
aux[:value].proteinas = ( (aux[:value].proteinas) * (aux2[:value]) )/100
|
83
|
+
aux[:value].hidratos = ( (aux[:value].hidratos) * (aux2[:value]) )/100
|
84
|
+
aux[:value].lipidos = ( (aux[:value].lipidos) * (aux2[:value]) )/100
|
85
|
+
calorias += aux[:value].valor_energetico
|
86
|
+
aux = aux[:next]
|
87
|
+
aux2 = aux2[:next]
|
88
|
+
end
|
89
|
+
|
90
|
+
return calorias.round(2)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Se obtiene el plato formateado
|
94
|
+
def to_s
|
95
|
+
aux = @lista_alimentos.head
|
96
|
+
aux2 = @lista_gramos.head
|
97
|
+
vector = []
|
98
|
+
vector << @nombre_plato
|
99
|
+
while (!aux.nil?)
|
100
|
+
vector << aux[:value].to_s
|
101
|
+
vector << aux2[:value]
|
102
|
+
aux = aux[:next]
|
103
|
+
aux2 = aux2[:next]
|
104
|
+
end
|
105
|
+
|
106
|
+
return vector
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
# encoding: utf-8
|
113
|
+
# Esta clase, que hereda de la clase Plato, calculará las emisiones diarias y anuales de los gases de efecto invernadero, y el uso del terreno# en referencia a los alimentos que componen cada plato.
|
114
|
+
#
|
115
|
+
# Author:: David Hernández Suárez (mailto:alu0101048239@ull.edu.es)
|
116
|
+
# Copyright:: Cretive Commons
|
117
|
+
# License:: Distributes under the same terms as Ruby
|
118
|
+
|
119
|
+
|
120
|
+
class Eficiencia_Energetica < Plato
|
121
|
+
|
122
|
+
attr_reader :nombre_plato, :lista_alimentos, :lista_gramos
|
123
|
+
include Comparable
|
124
|
+
|
125
|
+
# Se utiliza el módulo Comparable, comparando los alimentos en base a su huella nutricional.
|
126
|
+
def <=>(anOther)
|
127
|
+
#self.uso_terreno <=> anOther.uso_terreno
|
128
|
+
self.huella_nutricional <=> anOther.huella_nutricional
|
129
|
+
end
|
130
|
+
|
131
|
+
# Se asignan el nombre del plato, la lista de alimentos que lo contienen y la lista de gramos de cada alimento.
|
132
|
+
def initialize(nombre_plato, lista_alimentos, lista_gramos)
|
133
|
+
super(nombre_plato, lista_alimentos, lista_gramos)
|
134
|
+
end
|
135
|
+
|
136
|
+
# Se calculan las emisiones anuales de gases de efecto invernadero que produce el plato
|
137
|
+
def emisiones_gases_anuales
|
138
|
+
aux = @lista_alimentos.head
|
139
|
+
aux2 = @lista_gramos.head
|
140
|
+
suma_gases_anuales = 0
|
141
|
+
while (!aux.nil?)
|
142
|
+
suma_gases_anuales += aux[:value].auxiliar(aux2[:value])
|
143
|
+
aux = aux[:next]
|
144
|
+
aux2 = aux2[:next]
|
145
|
+
end
|
146
|
+
|
147
|
+
return suma_gases_anuales.round(2)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Se calculan las emisiones diarias de gases de efecto invernadero que produce el plato
|
151
|
+
def emisiones_gases_diarios
|
152
|
+
suma = (emisiones_gases_anuales / 365)
|
153
|
+
return suma.round(3)
|
154
|
+
end
|
155
|
+
|
156
|
+
# Se calcula el uso del terreno anual que produce el plato
|
157
|
+
def uso_terreno
|
158
|
+
aux = @lista_alimentos.head
|
159
|
+
aux2 = @lista_gramos.head
|
160
|
+
suma_terreno = 0
|
161
|
+
while (!aux.nil?)
|
162
|
+
suma_terreno += aux[:value].auxiliar2(aux2[:value])
|
163
|
+
aux = aux[:next]
|
164
|
+
aux2 = aux2[:next]
|
165
|
+
end
|
166
|
+
|
167
|
+
return suma_terreno.round(2)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Se obtiene la información de gases y terreno formateada
|
171
|
+
def to_s
|
172
|
+
"( #{self.emisiones_gases_anuales}, #{self.emisiones_gases_diarios}, #{self.uso_terreno} )"
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
# Se calcula la huella nutricional del plato
|
177
|
+
def huella_nutricional
|
178
|
+
if (valor_calorico < 670)
|
179
|
+
aux = 1
|
180
|
+
elsif (valor_calorico < 830)
|
181
|
+
aux = 2
|
182
|
+
else
|
183
|
+
aux = 3
|
184
|
+
end
|
185
|
+
|
186
|
+
if (emisiones_gases_anuales < 0.8)
|
187
|
+
aux2 = 1
|
188
|
+
elsif (emisiones_gases_anuales < 1.2)
|
189
|
+
aux2 = 2
|
190
|
+
else
|
191
|
+
aux2 = 3
|
192
|
+
end
|
193
|
+
|
194
|
+
return ((aux+aux2)/2.0).round(2)
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
end
|