Class: PlatoA
- Includes:
- Comparable
- Defined in:
- lib/nutriente/platoA.rb
Overview
Clase PlatoA (Plato Ambiental)
Instance Attribute Summary collapse
-
#co2 ⇒ Object
readonly
Returns the value of attribute co2.
-
#co2: ⇒ Object
readonly
Valor total de co2.
-
#listaAlimentos ⇒ Object
readonly
Returns the value of attribute listaAlimentos.
-
#listaAlimentos: ⇒ Object
readonly
lista de alimentos.
-
#listaGramos ⇒ Object
readonly
Returns the value of attribute listaGramos.
-
#listaGramos: ⇒ Object
readonly
lista de gramos.
-
#nombre ⇒ Object
readonly
Returns the value of attribute nombre.
-
#nombre: ⇒ Object
readonly
nombre del plato.
-
#terreno ⇒ Object
readonly
Returns the value of attribute terreno.
-
#terreno: ⇒ Object
readonly
terreno total.
Attributes inherited from PlatoE
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Metodo de comparación, devuelve -1 si es menor que other, +1 si es mayor y 0 si es igual, se utiliza para los mixins de comparable.
-
#huella_nutricional ⇒ Object
calculo de la huella nutricional, comprando la energía (vct) y el carbono(co2), realizando después la media.
-
#initialize(nombre, listaAlimentos, listaGramos) ⇒ PlatoA
constructor
Constructo que se le pasa por parametros el nombre del plato, una lista de alimentos y una lista de gramos.
-
#terrenoTotal ⇒ Object
calcular el uso del terreno total.
-
#to_s ⇒ Object
Formatear la salida de un plato ambiental como un string.
-
#valorTotalCO2 ⇒ Object
calcular el valor total de CO2.
Methods inherited from PlatoE
#porcentajeGlucidos, #porcentajeLipidos, #porcentajeProteinas, #valorCaloricoTotal
Constructor Details
#initialize(nombre, listaAlimentos, listaGramos) ⇒ PlatoA
Constructo que se le pasa por parametros el nombre del plato, una lista de alimentos y una lista de gramos
14 15 16 17 18 19 |
# File 'lib/nutriente/platoA.rb', line 14 def initialize(nombre, listaAlimentos, listaGramos) super(nombre, listaAlimentos, listaGramos) @co2 = valorTotalCO2 @terreno = terrenoTotal end |
Instance Attribute Details
#co2 ⇒ Object (readonly)
Returns the value of attribute co2.
10 11 12 |
# File 'lib/nutriente/platoA.rb', line 10 def co2 @co2 end |
#co2: ⇒ Object (readonly)
Valor total de co2
8 9 10 |
# File 'lib/nutriente/platoA.rb', line 8 def co2: @co2: end |
#listaAlimentos ⇒ Object (readonly)
Returns the value of attribute listaAlimentos.
10 11 12 |
# File 'lib/nutriente/platoA.rb', line 10 def listaAlimentos @listaAlimentos end |
#listaAlimentos: ⇒ Object (readonly)
lista de alimentos
8 9 10 |
# File 'lib/nutriente/platoA.rb', line 8 def listaAlimentos: @listaAlimentos: end |
#listaGramos ⇒ Object (readonly)
Returns the value of attribute listaGramos.
10 11 12 |
# File 'lib/nutriente/platoA.rb', line 10 def listaGramos @listaGramos end |
#listaGramos: ⇒ Object (readonly)
lista de gramos
8 9 10 |
# File 'lib/nutriente/platoA.rb', line 8 def listaGramos: @listaGramos: end |
#nombre ⇒ Object (readonly)
Returns the value of attribute nombre.
10 11 12 |
# File 'lib/nutriente/platoA.rb', line 10 def nombre @nombre end |
#nombre: ⇒ Object (readonly)
nombre del plato
8 9 10 |
# File 'lib/nutriente/platoA.rb', line 8 def nombre: @nombre: end |
#terreno ⇒ Object (readonly)
Returns the value of attribute terreno.
10 11 12 |
# File 'lib/nutriente/platoA.rb', line 10 def terreno @terreno end |
#terreno: ⇒ Object (readonly)
terreno total
8 9 10 |
# File 'lib/nutriente/platoA.rb', line 8 def terreno: @terreno: end |
Instance Method Details
#<=>(other) ⇒ Object
Metodo de comparación, devuelve -1 si es menor que other, +1 si es mayor y 0 si es igual, se utiliza para los mixins de comparable
53 54 55 |
# File 'lib/nutriente/platoA.rb', line 53 def <=>(other) self.huella_nutricional <=> other.huella_nutricional end |
#huella_nutricional ⇒ Object
calculo de la huella nutricional, comprando la energía (vct) y el carbono(co2), realizando después la media
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/nutriente/platoA.rb', line 58 def huella_nutricional @energia if self.vct< 670 @energia = 1 elsif self.vct >= 670 && self.vct < 830 @energia = 2 else @energia = 3 end @carbono if self.co2 < 800 @carbono = 1 elsif self.co2 >= 800 && self.co2 < 1200 @carbono = 2 else @carbono = 3 end return (@energia + @carbono)/2 end |
#terrenoTotal ⇒ Object
calcular el uso del terreno total
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/nutriente/platoA.rb', line 35 def terrenoTotal la = @listaAlimentos.head lg = listaGramos.head totalCO2 = 0.0 while la != nil do totalTerreno = totalCO2 + la.value.terreno * lg.value la = la.next lg = lg.next end return totalTerreno end |
#to_s ⇒ Object
Formatear la salida de un plato ambiental como un string
48 49 50 |
# File 'lib/nutriente/platoA.rb', line 48 def to_s "#{@nombre}, #{@listaAlimentos}, #{@listaGramos}, #{@vct}, #{@co2}, #{@terreno}" end |
#valorTotalCO2 ⇒ Object
calcular el valor total de CO2
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nutriente/platoA.rb', line 22 def valorTotalCO2 la = @listaAlimentos.head lg = listaGramos.head totalCO2 = 0.0 while la != nil do totalCO2 = totalCO2 + la.value.gei * lg.value la = la.next lg = lg.next end return totalCO2 end |