Class: PlatoE

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nutriente/platoE.rb

Overview

Clase PlatoE (Plato Energía)

Author:

  • Sergio Moreno Martín

Direct Known Subclasses

PlatoA

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, listaAlimentos, listaGramos) ⇒ PlatoE

Constructor que se le pasa por parámetro el nombre del alimento, una lista de alimentos y una lista de gramos



14
15
16
17
18
19
# File 'lib/nutriente/platoE.rb', line 14

def initialize(nombre, listaAlimentos, listaGramos)
    @nombre = nombre
    @listaAlimentos = listaAlimentos
    @listaGramos = listaGramos
    @vct = valorCaloricoTotal
end

Instance Attribute Details

#listaAlimentosObject (readonly)

Returns the value of attribute listaAlimentos.



10
11
12
# File 'lib/nutriente/platoE.rb', line 10

def listaAlimentos
  @listaAlimentos
end

#listaAlimentos:Object (readonly)

Devuelve una lista de alimentos

Returns:

  • (Object)

    the current value of listaAlimentos:



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

def listaAlimentos:
  @listaAlimentos:
end

#listaGramosObject (readonly)

Returns the value of attribute listaGramos.



10
11
12
# File 'lib/nutriente/platoE.rb', line 10

def listaGramos
  @listaGramos
end

#listaGramos:Object (readonly)

Devuelve una lista de gramos

Returns:

  • (Object)

    the current value of listaGramos:



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

def listaGramos:
  @listaGramos:
end

#nombreObject (readonly)

Returns the value of attribute nombre.



10
11
12
# File 'lib/nutriente/platoE.rb', line 10

def nombre
  @nombre
end

#nombre:Object (readonly)

Devuelve el nombre del plato

Returns:

  • (Object)

    the current value of nombre:



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

def nombre:
  @nombre:
end

#vctObject (readonly)

Returns the value of attribute vct.



10
11
12
# File 'lib/nutriente/platoE.rb', line 10

def vct
  @vct
end

#vct:Object (readonly)

Devuelve el valor calórico total

Returns:

  • (Object)

    the current value of vct:



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

def vct:
  @vct:
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



82
83
84
# File 'lib/nutriente/platoE.rb', line 82

def <=>(other)
    self.vct <=> other.vct
end

#porcentajeGlucidosObject

Calcular el porcentaje de glucidos segun la cantidad de gramos



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nutriente/platoE.rb', line 51

def porcentajeGlucidos
    total_glucidos = 0.0
    la = @listaAlimentos.head
    lg = @listaGramos.head
    while la != nil do
        total_glucidos += (la.value.carbohidratos * lg.value) / 100
        la = la.next
        lg = lg.next
    end
    total_gramos = listaGramos.reduce(:+)
    porcentajeGlucidos = ((total_glucidos / total_gramos)*100).round(2)
end

#porcentajeLipidosObject

Calcular el procentaje de lipidos según la cantidad de gramos



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nutriente/platoE.rb', line 37

def porcentajeLipidos
    total_lipidos = 0.0
    la = @listaAlimentos.head
    lg = @listaGramos.head
    while la != nil do
        total_lipidos += (la.value.lipidos * lg.value) / 100
        la = la.next
        lg = lg.next
    end
    total_gramos = listaGramos.reduce(:+)
    porcentajeLipidos = ((total_lipidos / total_gramos) * 100).round(2)
end

#porcentajeProteinasObject

cacular el porcentaje de proteinas según la cantidad de gramos



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nutriente/platoE.rb', line 22

def porcentajeProteinas
    total_proteinas = 0.0
    la = @listaAlimentos.head
    lg = @listaGramos.head

    while la != nil do
        total_proteinas += (la.value.proteinas * lg.value) / 100
        la = la.next
        lg = lg.next
    end
    total_gramos = listaGramos.reduce(:+)
    porcentajeProteinas = ((total_proteinas / total_gramos) * 100).round(2)
end

#to_sObject

Formatear la salidad de un plato tipo energía



77
78
79
# File 'lib/nutriente/platoE.rb', line 77

def to_s
    "#{@nombre}, #{@listaAlimentos}, #{@listaGramos}, #{@vct}"
end

#valorCaloricoTotalObject

calcular el valor clórico total del plato y todos sus alimentos



65
66
67
68
69
70
71
72
73
74
# File 'lib/nutriente/platoE.rb', line 65

def valorCaloricoTotal
    la = @listaAlimentos.head
    lg = @listaGramos.head
    while la != nil do
        resultado = (la.value.valorEnergetico * lg.value) / 100
        la = la.next
        lg = lg.next
    end
    return resultado
end