Class: Alimento::PlatoAmbiental

Inherits:
Plato
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/alimento/platoambiental.rb

Instance Attribute Summary collapse

Attributes inherited from Plato

#cantidades, #lista, #nombre

Instance Method Summary collapse

Methods inherited from Plato

#VCT, #porcentaje_carbohidratos, #porcentaje_lipidos, #porcentaje_proteinas

Constructor Details

#initialize(nombre, lista, cantidades) ⇒ PlatoAmbiental

Note:

Constructor de la clase que llama al de Plato y al propio

Returns a new instance of PlatoAmbiental

Parameters:

  • nombre

    Identificador del plato

  • lista

    Conjunto de alimentos del plato

  • cantidades

    Vector de cantidades de cada alimento



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

#emisionesObject (readonly)

Returns the value of attribute emisiones



9
10
11
# File 'lib/alimento/platoambiental.rb', line 9

def emisiones
  @emisiones
end

#terrenoObject (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

Note:

Comparador de las emisiones ambientales totales de cada plato

Returns Plato con mayores emisiones

Parameters:

  • otro

    Objeto del mismo tipo con el cual comparar

Returns:



25
26
27
# File 'lib/alimento/platoambiental.rb', line 25

def <=>(otro)
	emisiones_total <=> otro.emisiones_total
end

#emisiones_totalFloat

Note:

Calculo de las emisiones de gases del plato

Returns Emisiones totales del plato

Returns:

  • (Float)

    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_carbonoInteger

Note:

Calculo de la huella de carbono total del plato

Returns Indice segun la huella de carbono del plato

Returns:

  • (Integer)

    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_energiaInteger

Note:

Calculo del indice de huella nutricional del plato

Returns Indice resultante

Returns:

  • (Integer)

    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_nutricionalInteger

Note:

Calculo del indice medio entre todos los del plato

Returns Indice de media de los demas

Returns:

  • (Integer)

    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_totalFloat

Note:

Calculo del terreno ocupado por los alimentos del plato

Returns Terreno total de los alimentos del plato

Returns:

  • (Float)

    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_sString

Note:

Formateo del plato

Returns Datos del plato que son el nombre y energia total

Returns:

  • (String)

    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