Class: Alimento::PlatoAmbiental
- Includes:
- Comparable, Enumerable
- Defined in:
- lib/alimento/platoambiental.rb
Instance Attribute Summary collapse
-
#emisiones ⇒ Object
readonly
Returns the value of attribute emisiones.
-
#terreno ⇒ Object
readonly
Returns the value of attribute terreno.
Attributes inherited from Plato
Instance Method Summary collapse
-
#<=>(otro) ⇒ PlatoAmbiental
Plato con mayores emisiones.
-
#emisiones_total ⇒ Float
Emisiones totales del plato.
-
#huella_carbono ⇒ Integer
Indice segun la huella de carbono del plato.
-
#huella_energia ⇒ Integer
Indice resultante.
-
#huella_nutricional ⇒ Integer
Indice de media de los demas.
-
#initialize(nombre, lista, cantidades) ⇒ PlatoAmbiental
constructor
A new instance of PlatoAmbiental.
-
#terreno_total ⇒ Float
Terreno total de los alimentos del plato.
-
#to_s ⇒ String
Datos del plato que son el nombre y energia total.
Methods inherited from Plato
#VCT, #porcentaje_carbohidratos, #porcentaje_lipidos, #porcentaje_proteinas
Constructor Details
#initialize(nombre, lista, cantidades) ⇒ PlatoAmbiental
Constructor de la clase que llama al de Plato y al propio
Returns a new instance of PlatoAmbiental
16 17 18 19 20 |
# File 'lib/alimento/platoambiental.rb', line 16 def initialize(nombre, lista, cantidades) super(nombre, lista, cantidades) @emisiones = emisiones_total @terreno = terreno_total end |
Instance Attribute Details
#emisiones ⇒ Object (readonly)
Returns the value of attribute emisiones
9 10 11 |
# File 'lib/alimento/platoambiental.rb', line 9 def emisiones @emisiones end |
#terreno ⇒ Object (readonly)
Returns the value of attribute terreno
9 10 11 |
# File 'lib/alimento/platoambiental.rb', line 9 def terreno @terreno end |
Instance Method Details
#<=>(otro) ⇒ PlatoAmbiental
Comparador de las emisiones ambientales totales de cada plato
Returns Plato con mayores emisiones
25 26 27 |
# File 'lib/alimento/platoambiental.rb', line 25 def <=>(otro) emisiones_total <=> otro.emisiones_total end |
#emisiones_total ⇒ Float
Calculo de las emisiones de gases del plato
Returns Emisiones totales del plato
32 33 34 35 36 37 38 39 40 |
# File 'lib/alimento/platoambiental.rb', line 32 def emisiones_total total_emisiones = 0 i = 0 @lista.each{|iter| total_emisiones += (iter.value.gei * @cantidades[i]/100) i += 1 } return total_emisiones.round(1) end |
#huella_carbono ⇒ Integer
Calculo de la huella de carbono total del plato
Returns Indice segun la huella de carbono del plato
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/alimento/platoambiental.rb', line 73 def huella_carbono emi_total_dia = ((emisiones_total()*1000)/365) if emi_total_dia < 800 return 1 elsif (800..1200) === emi_total_dia return 2 else return 3 end end |
#huella_energia ⇒ Integer
Calculo del indice de huella nutricional del plato
Returns Indice resultante
60 61 62 63 64 65 66 67 68 |
# File 'lib/alimento/platoambiental.rb', line 60 def huella_energia if VCT() < 670 return 1 elsif (670..830) === VCT() return 2 else return 3 end end |
#huella_nutricional ⇒ Integer
Calculo del indice medio entre todos los del plato
Returns Indice de media de los demas
87 88 89 |
# File 'lib/alimento/platoambiental.rb', line 87 def huella_nutricional return ((huella_carbono + huella_energia) / 2).floor end |
#terreno_total ⇒ Float
Calculo del terreno ocupado por los alimentos del plato
Returns Terreno total de los alimentos del plato
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/alimento/platoambiental.rb', line 45 def terreno_total ter_array = @lista.collect{|iter| iter.value.terreno} total_terreno = [] i = 0 while i < @cantidades.length do total_terreno.push(ter_array[i] * (@cantidades[i]/100)) i +=1 end return (total_terreno.sum).round(1) end |
#to_s ⇒ String
Formateo del plato
Returns Datos del plato que son el nombre y energia total
94 95 96 97 |
# File 'lib/alimento/platoambiental.rb', line 94 def to_s string = "La eficiencia energetica de '#{nombre}' es: #{VCT()}" return string end |