alimentos_diego_algomas 0.1.3
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/.coveralls.yml +2 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +97 -0
- data/Guardfile +83 -0
- data/README.md +57 -0
- data/Rakefile +6 -0
- data/alimentos.gemspec +38 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimentos.html +115 -0
- data/docs/Alimentos/Alimentos.html +376 -0
- data/docs/Alimentos/Error.html +106 -0
- data/docs/Gemfile.html +99 -0
- data/docs/Gemfile_lock.html +180 -0
- data/docs/Guardfile.html +166 -0
- data/docs/List.html +120 -0
- data/docs/List/Error.html +106 -0
- data/docs/List/List.html +495 -0
- data/docs/Menu.html +115 -0
- data/docs/Menu/Error.html +106 -0
- data/docs/Menu/Menu.html +512 -0
- data/docs/Object.html +199 -0
- data/docs/Plato.html +115 -0
- data/docs/Plato/Error.html +106 -0
- data/docs/Plato/Plato.html +478 -0
- data/docs/Plato/PlatoAmbiental.html +374 -0
- data/docs/README_md.html +155 -0
- data/docs/Rakefile.html +101 -0
- data/docs/bin/setup.html +101 -0
- data/docs/created.rid +17 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +619 -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 +132 -0
- data/docs/js/darkfish.js +84 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +110 -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 +345 -0
- data/lib/alimentos.rb +29 -0
- data/lib/alimentos/alimentos.rb +36 -0
- data/lib/alimentos/dsl.rb +123 -0
- data/lib/alimentos/dslmenu.rb +60 -0
- data/lib/alimentos/list.rb +104 -0
- data/lib/alimentos/menu.rb +62 -0
- data/lib/alimentos/plato.rb +93 -0
- data/lib/alimentos/platoAmbiental.rb +64 -0
- data/lib/alimentos/version.rb +15 -0
- metadata +243 -0
data/lib/alimentos.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
require "alimentos/version"
|
3
|
+
require "alimentos/alimentos.rb"
|
4
|
+
require "alimentos/list.rb"
|
5
|
+
require "alimentos/plato.rb"
|
6
|
+
require "alimentos/platoAmbiental.rb"
|
7
|
+
require "alimentos/menu.rb"
|
8
|
+
require "alimentos/dsl.rb"
|
9
|
+
require "alimentos/dslmenu.rb"
|
10
|
+
|
11
|
+
module Alimentos
|
12
|
+
class Error < StandardError; end
|
13
|
+
# Your code goes here...
|
14
|
+
end
|
15
|
+
module List
|
16
|
+
class Error < StandardError; end
|
17
|
+
end
|
18
|
+
module Plato
|
19
|
+
class Error < StandardError;end
|
20
|
+
end
|
21
|
+
module Menu
|
22
|
+
class Error < StandardError;end
|
23
|
+
end
|
24
|
+
module Dsl
|
25
|
+
class Error < StandardError;end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
##
|
2
|
+
# Modulo donde se encuentra la clase de alimentos
|
3
|
+
|
4
|
+
module Alimentos
|
5
|
+
##
|
6
|
+
# Clase alimentos donde se guardan las propiedades del mismo
|
7
|
+
class Alimentos
|
8
|
+
include Comparable
|
9
|
+
attr_reader :nombre,:proteinas,:carbohidratos,:lipidos,:emisiones,:m2
|
10
|
+
def initialize (nombre,proteinas,carbohidratos,lipidos,emisiones,m2)
|
11
|
+
@nombre = nombre
|
12
|
+
@proteinas = proteinas
|
13
|
+
@carbohidratos = carbohidratos
|
14
|
+
@lipidos = lipidos
|
15
|
+
@emisiones = emisiones
|
16
|
+
@m2 = m2
|
17
|
+
|
18
|
+
end
|
19
|
+
##
|
20
|
+
# Metodo que calcula las kcal de un alimento
|
21
|
+
def calorias()
|
22
|
+
kcal = (@proteinas*4)+(@lipidos*9)+(@carbohidratos*4)
|
23
|
+
kcal.round(2)
|
24
|
+
end
|
25
|
+
##
|
26
|
+
# Serializador de un alimento
|
27
|
+
def to_s()
|
28
|
+
"#{@nombre}"
|
29
|
+
end
|
30
|
+
##
|
31
|
+
# Permite comparar entre alimentos
|
32
|
+
def <=>(other)
|
33
|
+
calorias()<=> other.calorias()
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require "alimentos/list.rb"
|
2
|
+
module Dsl
|
3
|
+
class Platodsl
|
4
|
+
include List
|
5
|
+
attr_accessor :nombre,:alimentos,:cantidades,:kcal
|
6
|
+
##
|
7
|
+
# Esta clase es comparable entre ellas
|
8
|
+
include Comparable
|
9
|
+
def initialize(nombre,&block)
|
10
|
+
@nombre = nombre
|
11
|
+
@alimentos = List.new()
|
12
|
+
@cantidades = List.new()
|
13
|
+
|
14
|
+
if block_given?
|
15
|
+
if block.arity == 1
|
16
|
+
yield self
|
17
|
+
else
|
18
|
+
instance_eval(&block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def alimento(aliment, options={})
|
23
|
+
@alimentos.push(aliment)
|
24
|
+
@cantidades.push(options[:cantidad]) if options[:cantidad]
|
25
|
+
@kcal=calculoCalorico()
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Realiza el calculo de las calorias totales del plato
|
30
|
+
def calculoCalorico()
|
31
|
+
calorias = @alimentos.collect { |x| x.calorias()}
|
32
|
+
cantidades = @cantidades.collect{ |x| x}
|
33
|
+
for i in 0...cantidades.size() do
|
34
|
+
calorias[i]=calorias[i]*0.01*cantidades[i]
|
35
|
+
end
|
36
|
+
calorias.sum
|
37
|
+
end
|
38
|
+
##
|
39
|
+
# Realiza el calculo del porcentaje de proteinas que tiene
|
40
|
+
def porproteinas()
|
41
|
+
proteinas = @alimentos.collect { |x| x.proteinas}
|
42
|
+
cantidades = @cantidades.collect{|x| x}
|
43
|
+
for i in 0...proteinas.size() do
|
44
|
+
proteinas[i] = proteinas[i]*cantidades[i]*0.01
|
45
|
+
end
|
46
|
+
((proteinas.sum*4/@kcal)*100).round(2)
|
47
|
+
end
|
48
|
+
##
|
49
|
+
# Realiza el calculo del porcentaje de lipidos que tiene
|
50
|
+
def porlipidos()
|
51
|
+
lipidos = @alimentos.collect { |x| x.lipidos}
|
52
|
+
cantidades = @cantidades.collect{|x| x}
|
53
|
+
for i in 0...lipidos.size() do
|
54
|
+
lipidos[i]=lipidos[i]*cantidades[i]*0.01
|
55
|
+
end
|
56
|
+
((lipidos.sum*9/@kcal)*100).round(2)
|
57
|
+
end
|
58
|
+
def emisiones()
|
59
|
+
emisiones= @alimentos.collect{ |x| x.emisiones }
|
60
|
+
cantidades = @cantidades.collect{|x| x}
|
61
|
+
for i in 0...emisiones.size() do
|
62
|
+
emisiones[i]=emisiones[i]*cantidades[i]*0.01
|
63
|
+
end
|
64
|
+
(emisiones.sum).round(2)
|
65
|
+
end
|
66
|
+
##
|
67
|
+
# Calcula los metros cuadrados que gasta cada plato
|
68
|
+
def m2()
|
69
|
+
m2= @alimentos.collect{ |x| x.m2}
|
70
|
+
cantidades = @cantidades.collect{|x| x}
|
71
|
+
for i in 0...m2.size() do
|
72
|
+
m2[i]=m2[i]*cantidades[i]*0.01
|
73
|
+
end
|
74
|
+
(m2.sum).round(2)
|
75
|
+
end
|
76
|
+
##
|
77
|
+
# Realiza el calculo del porcentaje de carbohidratos que tiene
|
78
|
+
def porcarbohidratos()
|
79
|
+
carbohidratos = @alimentos.collect{ |x| x.carbohidratos }
|
80
|
+
cantidades = @cantidades.collect{|x| x}
|
81
|
+
for i in 0...carbohidratos.size() do
|
82
|
+
carbohidratos[i]=carbohidratos[i]*cantidades[i]*0.01
|
83
|
+
end
|
84
|
+
((carbohidratos.sum*4/@kcal)*100).round(2)
|
85
|
+
end
|
86
|
+
def huella()
|
87
|
+
ienergia=0
|
88
|
+
icarbono=0
|
89
|
+
if @kcal<670
|
90
|
+
ienergia+=1
|
91
|
+
elsif @kcal > 830
|
92
|
+
ienergia+=3
|
93
|
+
else
|
94
|
+
ienergia+=2
|
95
|
+
end
|
96
|
+
if emisiones()<800
|
97
|
+
icarbono+=1
|
98
|
+
elsif emisiones()>1200
|
99
|
+
icarbono+=3
|
100
|
+
else
|
101
|
+
icarbono+=2
|
102
|
+
end
|
103
|
+
huellapropia= (ienergia+icarbono)/2
|
104
|
+
huellapropia
|
105
|
+
end
|
106
|
+
##
|
107
|
+
# Serializa el plato
|
108
|
+
def to_s()
|
109
|
+
output = "#{@nombre}:\n"
|
110
|
+
@alimentos.zip(@cantidades).each do |aliment,cantidad|
|
111
|
+
output<<"\t\t#{aliment}: #{cantidad}g\n"
|
112
|
+
end
|
113
|
+
output << "\t\tValor energético: #{@kcal}kcal\n"
|
114
|
+
output << "\t\tHuella: #{huella()}"
|
115
|
+
output
|
116
|
+
end
|
117
|
+
##
|
118
|
+
# Permite comparar entre distintos platos según las kcal
|
119
|
+
def <=>(other)
|
120
|
+
@kcal<=>other.kcal
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Dsl
|
2
|
+
class MenuDsl
|
3
|
+
attr_accessor :nombre,:platos,:precios
|
4
|
+
include List
|
5
|
+
def initialize(nombre, &block)
|
6
|
+
@nombre = nombre
|
7
|
+
@precios = List.new()
|
8
|
+
@platos = List.new()
|
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 plato(plate,options={})
|
19
|
+
@platos.push(plate)
|
20
|
+
@precios.push(options[:price]) if options[:price]
|
21
|
+
end
|
22
|
+
def precio()
|
23
|
+
@precios.collect{|x| x}.sum
|
24
|
+
end
|
25
|
+
def energetico()
|
26
|
+
@platos.collect{|x| x.kcal}.sum
|
27
|
+
end
|
28
|
+
def porproteinas()
|
29
|
+
@platos.collect{|x| x.porproteinas()}.sum
|
30
|
+
end
|
31
|
+
def porlipidos()
|
32
|
+
@platos.collect{|x| x.porlipidos()}.sum
|
33
|
+
end
|
34
|
+
def porcarbohidratos()
|
35
|
+
@platos.collect{|x| x.porcarbohidratos()}.sum
|
36
|
+
end
|
37
|
+
def m2()
|
38
|
+
@platos.collect{|x| x.m2()}.sum
|
39
|
+
end
|
40
|
+
def emisiones()
|
41
|
+
@platos.collect{|x| x.emisiones()}.sum
|
42
|
+
end
|
43
|
+
def to_s()
|
44
|
+
output = "#{@nombre}"
|
45
|
+
output << ":\n"
|
46
|
+
@platos.zip(@precios).each do |plato,precio|
|
47
|
+
output << "\t#{plato}\n"
|
48
|
+
end
|
49
|
+
output<< "Precio: #{precio()}\n"
|
50
|
+
output<< "Proteinas: #{porproteinas()}g\n"
|
51
|
+
output<< "Lipidos: #{porlipidos()}g\n"
|
52
|
+
output<< "Carbohidratos: #{porcarbohidratos()}g\n"
|
53
|
+
output<< "Kcal: #{energetico()}\n"
|
54
|
+
output<< "M2: #{m2()}\n"
|
55
|
+
output<< "Emisiones: #{emisiones()}\n"
|
56
|
+
output
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
##
|
2
|
+
# Modulo lista donde se encuentra la clase lista y el diseño de un nodo
|
3
|
+
module List
|
4
|
+
Node = Struct.new(:value,:next,:prev)
|
5
|
+
##
|
6
|
+
# Clase lista donde se implementa una clase constituida por una lista doblemente enlazada de elementos
|
7
|
+
class List
|
8
|
+
##
|
9
|
+
# Incluye el modulo enumerable para permitir la iteración sobre la clase
|
10
|
+
include Enumerable
|
11
|
+
attr_reader :head,:tail,:lenght
|
12
|
+
def initialize ()
|
13
|
+
@head = nil
|
14
|
+
@tail = nil
|
15
|
+
@lenght = 0
|
16
|
+
end
|
17
|
+
##
|
18
|
+
# Permite insertar un valor en la cola
|
19
|
+
def push (valor)
|
20
|
+
toinsert = Node.new(valor,nil,nil)
|
21
|
+
if @lenght == 0
|
22
|
+
@lenght= @lenght+1
|
23
|
+
toinsert.next = nil
|
24
|
+
toinsert.prev = nil
|
25
|
+
@head = toinsert
|
26
|
+
@tail = toinsert
|
27
|
+
else
|
28
|
+
@lenght = @lenght+1
|
29
|
+
@tail.next = toinsert
|
30
|
+
toinsert.prev = @tail
|
31
|
+
toinsert.next = nil
|
32
|
+
@tail = toinsert
|
33
|
+
end
|
34
|
+
end
|
35
|
+
##
|
36
|
+
# Permite insertar un array de elementos en la cola
|
37
|
+
def push_array(values)
|
38
|
+
values.each do |item|
|
39
|
+
toinsert = Node.new(item,nil,nil)
|
40
|
+
if @lenght == 0
|
41
|
+
@lenght= @lenght+1
|
42
|
+
toinsert.next = nil
|
43
|
+
toinsert.prev = nil
|
44
|
+
@head = toinsert
|
45
|
+
@tail = toinsert
|
46
|
+
else
|
47
|
+
@lenght = @lenght+1
|
48
|
+
@tail.next = toinsert
|
49
|
+
toinsert.prev = @tail
|
50
|
+
toinsert.next = nil
|
51
|
+
@tail = toinsert
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
##
|
56
|
+
# Permite extraer la cabeza y la devuelve
|
57
|
+
def pop_head()
|
58
|
+
if @lenght == 1
|
59
|
+
aux = @head
|
60
|
+
@lenght = 0
|
61
|
+
@head = nil
|
62
|
+
@tail = nil
|
63
|
+
return aux
|
64
|
+
elsif @lenght > 1
|
65
|
+
aux = @head
|
66
|
+
@lenght = @lenght-1
|
67
|
+
@head = aux.next
|
68
|
+
return aux
|
69
|
+
else
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
##
|
74
|
+
# Permite extraer la cola y la devuelve ese elemento
|
75
|
+
def pop_tail()
|
76
|
+
if @lenght == 1
|
77
|
+
aux = @head
|
78
|
+
@lenght = 0
|
79
|
+
@head = nil
|
80
|
+
@tail = nil
|
81
|
+
return aux
|
82
|
+
elsif @lenght > 1
|
83
|
+
aux = @tail
|
84
|
+
@lenght = @lenght-1
|
85
|
+
@tail = aux.prev
|
86
|
+
return aux
|
87
|
+
else
|
88
|
+
return nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
def each
|
92
|
+
aux = @head
|
93
|
+
while(!aux.nil?)
|
94
|
+
yield aux.value
|
95
|
+
aux = aux.next
|
96
|
+
end
|
97
|
+
end
|
98
|
+
##
|
99
|
+
# Devuelve el tamaño de la lista
|
100
|
+
def size()
|
101
|
+
@lenght-1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
##
|
2
|
+
# Modulo donde se encuentra la clase menú (practica 8)
|
3
|
+
# Actualemente en desuso
|
4
|
+
module Menu
|
5
|
+
##
|
6
|
+
# Clase Menu donde se almacenaban una lista con los platos y la suma calórica de os mismos
|
7
|
+
class Menu
|
8
|
+
attr_reader :nombre,:platos,:kcal,:proteinas,:lipidos,:carbohidratos
|
9
|
+
include Comparable,Enumerable
|
10
|
+
def initialize(nombre,platos)
|
11
|
+
@platos = List::List.new()
|
12
|
+
@platos.push_array(platos)
|
13
|
+
@nombre = nombre
|
14
|
+
@proteinas = getProteinas()
|
15
|
+
@lipidos = getLipidos()
|
16
|
+
@carbohidratos = getCarbohidratos()
|
17
|
+
@kcal = getKcal()
|
18
|
+
end
|
19
|
+
##
|
20
|
+
# calcula las Kcal del menú
|
21
|
+
def getKcal()
|
22
|
+
kalorias = @platos.collect{|x| x.kcal}
|
23
|
+
(kalorias.sum).round(2)
|
24
|
+
end
|
25
|
+
##
|
26
|
+
# Calcula la cantidad de lípidos
|
27
|
+
def getLipidos()
|
28
|
+
lipids = @platos.collect{|x| x.porlipidos()}
|
29
|
+
(lipids.sum/lipids.size()).round(2)
|
30
|
+
end
|
31
|
+
##
|
32
|
+
# calcula la cantidad de proteinas
|
33
|
+
def getProteinas()
|
34
|
+
proteins = @platos.collect{|x| x.porproteinas()}
|
35
|
+
(proteins.sum/proteins.size()).round(2)
|
36
|
+
end
|
37
|
+
##
|
38
|
+
# calcula la cantidad de carbohidratos
|
39
|
+
def getCarbohidratos()
|
40
|
+
carbs = @platos.collect{|x| x.porcarbohidratos()}
|
41
|
+
(carbs.sum/carbs.size()).round(2)
|
42
|
+
end
|
43
|
+
##
|
44
|
+
# Compara entre distintos menus por las kcal
|
45
|
+
def <=>(other)
|
46
|
+
kcal<=>other.kcal
|
47
|
+
end
|
48
|
+
## Transforma en un strig el menú
|
49
|
+
def to_s
|
50
|
+
"Menu: #{@nombre}\n Proteinas: #{@proteinas}%\nCarbohidratos:#{@carbohidratos}%\nLipidos:#{@lipidos}%\nKcal:#{@kcal}"
|
51
|
+
end
|
52
|
+
##
|
53
|
+
#Implementa el enumerable del menu
|
54
|
+
def each
|
55
|
+
aux = @platos.head
|
56
|
+
while(!aux.nil?)
|
57
|
+
yield aux.value
|
58
|
+
aux = aux.next
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "alimentos/list.rb"
|
2
|
+
require "alimentos/alimentos.rb"
|
3
|
+
##
|
4
|
+
# Modulo donde se encuentran la clase plato y plato ambiental
|
5
|
+
module Plato
|
6
|
+
##
|
7
|
+
# Clase plato donde se encuentran los platos dormados por sus alimentos y sus cantidades
|
8
|
+
class Plato
|
9
|
+
include List
|
10
|
+
attr_reader :nombre,:alimentos,:cantidades,:kcal
|
11
|
+
##
|
12
|
+
# Esta clase es comparable entre ellas
|
13
|
+
include Comparable
|
14
|
+
def initialize(nombre,alimentos,cantidades)
|
15
|
+
@nombre = nombre
|
16
|
+
@alimentos = List.new()
|
17
|
+
@cantidades = List.new()
|
18
|
+
@alimentos.push_array(alimentos)
|
19
|
+
@cantidades.push_array(cantidades)
|
20
|
+
@kcal = calculoCalorico()
|
21
|
+
|
22
|
+
end
|
23
|
+
##
|
24
|
+
# Realiza el calculo de las calorias totales del plato
|
25
|
+
def calculoCalorico()
|
26
|
+
calorias = @alimentos.collect { |x| x.calorias()}
|
27
|
+
cantidades = @cantidades.collect{ |x| x}
|
28
|
+
for i in 0...cantidades.size() do
|
29
|
+
calorias[i]=calorias[i]*0.01*cantidades[i]
|
30
|
+
end
|
31
|
+
calorias.sum
|
32
|
+
end
|
33
|
+
##
|
34
|
+
# Realiza el calculo del porcentaje de proteinas que tiene
|
35
|
+
def porproteinas()def huella()
|
36
|
+
ienergia=0
|
37
|
+
icarbono=0
|
38
|
+
if @kcal<670
|
39
|
+
ienergia+=1
|
40
|
+
elsif @kcal > 830
|
41
|
+
ienergia+=3
|
42
|
+
else
|
43
|
+
ienergia+=2
|
44
|
+
end
|
45
|
+
if emisiones()<800
|
46
|
+
icarbono+=1
|
47
|
+
elsif emisiones()>1200
|
48
|
+
icarbono+=3
|
49
|
+
else
|
50
|
+
icarbono+=2
|
51
|
+
end
|
52
|
+
huellapropia= (ienergia+icarbono)/2
|
53
|
+
huellapropia
|
54
|
+
end
|
55
|
+
proteinas = @alimentos.collect { |x| x.proteinas}
|
56
|
+
cantidades = @cantidades.collect{|x| x}
|
57
|
+
for i in 0...proteinas.size() do
|
58
|
+
proteinas[i] = proteinas[i]*cantidades[i]*0.01
|
59
|
+
end
|
60
|
+
((proteinas.sum*4/@kcal)*100).round(2)
|
61
|
+
end
|
62
|
+
##
|
63
|
+
# Realiza el calculo del porcentaje de lipidos que tiene
|
64
|
+
def porlipidos()
|
65
|
+
lipidos = @alimentos.collect { |x| x.lipidos}
|
66
|
+
cantidades = @cantidades.collect{|x| x}
|
67
|
+
for i in 0...lipidos.size() do
|
68
|
+
lipidos[i]=lipidos[i]*cantidades[i]*0.01
|
69
|
+
end
|
70
|
+
((lipidos.sum*9/@kcal)*100).round(2)
|
71
|
+
end
|
72
|
+
##
|
73
|
+
# Realiza el calculo del porcentaje de carbohidratos que tiene
|
74
|
+
def porcarbohidratos()
|
75
|
+
carbohidratos = @alimentos.collect{ |x| x.carbohidratos }
|
76
|
+
cantidades = @cantidades.collect{|x| x}
|
77
|
+
for i in 0...carbohidratos.size() do
|
78
|
+
carbohidratos[i]=carbohidratos[i]*cantidades[i]*0.01
|
79
|
+
end
|
80
|
+
((carbohidratos.sum*4/@kcal)*100).round(2)
|
81
|
+
end
|
82
|
+
##
|
83
|
+
# Serializa el plato
|
84
|
+
def to_s()
|
85
|
+
"#{nombre}: #{alimentos.collect{|x| x.nombre}.join(",")} #{@kcal}kcal"
|
86
|
+
end
|
87
|
+
##
|
88
|
+
# Permite comparar entre distintos platos según las kcal
|
89
|
+
def <=>(other)
|
90
|
+
@kcal<=>other.kcal
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|