Class: PlatoA

Inherits:
PlatoE show all
Includes:
Comparable
Defined in:
lib/nutriente/platoA.rb

Overview

Clase PlatoA (Plato Ambiental)

Instance Attribute Summary collapse

Attributes inherited from PlatoE

#vct, #vct:

Instance Method Summary collapse

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

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

Returns:

  • (Object)

    the current value of co2:



8
9
10
# File 'lib/nutriente/platoA.rb', line 8

def co2:
  @co2:
end

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

Returns:

  • (Object)

    the current value of listaAlimentos:



8
9
10
# File 'lib/nutriente/platoA.rb', line 8

def listaAlimentos:
  @listaAlimentos:
end

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

Returns:

  • (Object)

    the current value of listaGramos:



8
9
10
# File 'lib/nutriente/platoA.rb', line 8

def listaGramos:
  @listaGramos:
end

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

Returns:

  • (Object)

    the current value of nombre:



8
9
10
# File 'lib/nutriente/platoA.rb', line 8

def nombre:
  @nombre:
end

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

Returns:

  • (Object)

    the current value of terreno:



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_nutricionalObject

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

#terrenoTotalObject

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_sObject

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

#valorTotalCO2Object

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