Class: Tabla

Inherits:
Object
  • Object
show all
Includes:
Comparable, Enumerable
Defined in:
lib/alu0100406580_nutricion/tabla.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grasas, grasasSat, hidratos, azucares, proteinas, sal) ⇒ Tabla

Returns a new instance of Tabla.



30
31
32
33
34
35
36
# File 'lib/alu0100406580_nutricion/tabla.rb', line 30

def initialize(grasas, grasasSat, hidratos, azucares, proteinas, sal)
    @grasas, @grasasSat, @hidratos, @azucares, @proteinas, @sal = grasas, grasasSat, hidratos, azucares, proteinas, sal
    @valEnerKJ = ((@grasas*37)+(@hidratos*17)+(@proteinas*17))
    @valEnerKcal = ((@grasas*9)+(@hidratos*4)+(@proteinas*4))
    @valEnerKJTotal = ((@grasas*37)+(@hidratos*17)+(@proteinas*17)+(@sal*25)+(grasasMonoinsaturadas*37)+(grasasPoli*37)+(poliAlcoholes*10)+(almidon*17)+(fibra*8))
    @valEnerKcalTotal = ((@grasas*9)+(@hidratos*4)+(@proteinas*4)+(@sal*6)+(grasasMonoinsaturadas*9)+(grasasPoli*9)+(poliAlcoholes*2.4)+(almidon*4)+(fibra*2))
end

Instance Attribute Details

#almidonObject

Returns the value of attribute almidon.



28
29
30
# File 'lib/alu0100406580_nutricion/tabla.rb', line 28

def almidon
  @almidon
end

#azucaresObject (readonly)

Returns the value of attribute azucares.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def azucares
  @azucares
end

#fibraObject

Returns the value of attribute fibra.



28
29
30
# File 'lib/alu0100406580_nutricion/tabla.rb', line 28

def fibra
  @fibra
end

#grasasObject (readonly)

Returns the value of attribute grasas.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def grasas
  @grasas
end

#grasasMonoinsaturadasObject

Returns the value of attribute grasasMonoinsaturadas.



28
29
30
# File 'lib/alu0100406580_nutricion/tabla.rb', line 28

def grasasMonoinsaturadas
  @grasasMonoinsaturadas
end

#grasasPoliObject

Returns the value of attribute grasasPoli.



28
29
30
# File 'lib/alu0100406580_nutricion/tabla.rb', line 28

def grasasPoli
  @grasasPoli
end

#grasasSatObject (readonly)

Returns the value of attribute grasasSat.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def grasasSat
  @grasasSat
end

#hidratosObject (readonly)

Returns the value of attribute hidratos.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def hidratos
  @hidratos
end

#mineralesObject

Returns the value of attribute minerales.



28
29
30
# File 'lib/alu0100406580_nutricion/tabla.rb', line 28

def minerales
  @minerales
end

#poliAlcoholesObject

Returns the value of attribute poliAlcoholes.



28
29
30
# File 'lib/alu0100406580_nutricion/tabla.rb', line 28

def poliAlcoholes
  @poliAlcoholes
end

#proteinasObject (readonly)

Returns the value of attribute proteinas.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def proteinas
  @proteinas
end

#salObject (readonly)

Returns the value of attribute sal.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def sal
  @sal
end

#valEnerKcalObject (readonly)

Returns the value of attribute valEnerKcal.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def valEnerKcal
  @valEnerKcal
end

#valEnerKJObject (readonly)

Returns the value of attribute valEnerKJ.



27
28
29
# File 'lib/alu0100406580_nutricion/tabla.rb', line 27

def valEnerKJ
  @valEnerKJ
end

#vitaminasObject

Returns the value of attribute vitaminas.



28
29
30
# File 'lib/alu0100406580_nutricion/tabla.rb', line 28

def vitaminas
  @vitaminas
end

Instance Method Details

#<=>(other) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/alu0100406580_nutricion/tabla.rb', line 95

def <=>(other)
    return nil unless other.instance_of? Tabla
    mayor = 0
    menor = 0

    mayor += 1 if self.grasas > other.grasas
    mayor += 1 if self.grasasSat > other.grasasSat
    mayor += 1 if self.hidratos > other.hidratos
    mayor += 1 if self.azucares > other.azucares
    mayor += 1 if self.proteinas > other.proteinas
    mayor += 1 if self.sal > other.sal
    mayor += 1 if self.valEnerKJ > other.valEnerKJ
    mayor += 1 if self.valEnerKcal > other.valEnerKcal

    menor += 1 if self.grasas < other.grasas
    menor += 1 if self.grasasSat < other.grasasSat
    menor += 1 if self.hidratos < other.hidratos
    menor += 1 if self.azucares < other.azucares
    menor += 1 if self.proteinas < other.proteinas
    menor += 1 if self.sal < other.sal
    menor += 1 if self.valEnerKJ < other.valEnerKJ
    menor += 1 if self.valEnerKcal < other.valEnerKcal


    return mayor <=> menor if ((mayor && menor) != 0)
    return 0 <=> 0
end

#ingestaObject



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/alu0100406580_nutricion/tabla.rb', line 82

def ingesta
    valKJing = ((@valEnerKJ * 100) / 8400)
    valKCing = ((@valEnerKcal * 100) / 2000)
    grasasing = ((@grasas * 100) / 70)
    grasasSating = ((@grasasSat * 20) / 20)
    hidratosing = ((@hidratos * 100) / 260)
    azucaresing = ((@azucares * 100) / 90)
    proteinasing = ((@proteinas * 100) / 50)
    saling = ((@sal * 100) / 6)

    return "Ingesta de referencia: Valor energético: #{valKJing}%KJ/#{valKCing}%Kcal, Grasa total: #{grasasing.round(2)}%, Ácidos grasos saturados: #{grasasSating}, Hidratos de carbono: #{hidratosing.round(2)}%, Azúcares: #{azucaresing}%, Proteínas: #{proteinasing}, Sal: #{saling.round(2)}"
end

#porciones(porcion) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/alu0100406580_nutricion/tabla.rb', line 70

def porciones(porcion)
    valKJpor = ((@valEnerKJ * porcion) / 100)
    valKCpor = ((@valEnerKcal * porcion) / 100)
    grasaspor = ((@grasas * porcion) / 100)
    grasasSatpor = ((@grasasSat * porcion) / 100)
    hidratospor = ((@hidratos * porcion) / 100)
    azucarespor = ((@azucares * porcion) / 100)
    proteinaspor = ((@proteinas * porcion) / 100)
    salpor = ((@sal * porcion) / 100)
    return "cada porcion de #{porcion} tiene: Valor energetico:#{valKJpor}KJ/#{valKCpor}, grasas: #{grasaspor}, grasas saturadas: #{grasasSatpor}, hidratos de carbono: #{hidratospor}, azucares: #{azucarespor}, proteinas: #{proteinaspor}, sal: #{salpor}"
end

#to_sObject



66
67
68
# File 'lib/alu0100406580_nutricion/tabla.rb', line 66

def to_s
    return "El valor energético: #{@valEnerKJ}KJ/#{@valEnerKcal}Kcal Cantidad de grasas: #{@grasas} Cantidad de grasas saturadas: #{@grasasSat} Hidratos de carbono: #{@hidratos} Azúcares: #{@azucares} Proteínas: #{@proteinas} Sal: #{@sal}"
end