Class: IndiceGlucemico
Overview
Esta clase permite calcular el indice glucémico de un alimento. Hereda de la clase comida.
Instance Attribute Summary collapse
-
#dat ⇒ Object
readonly
Permite acceder a los atributos de la clase en forma de lectura.
Attributes inherited from Comida
#comida, #glucidos, #lipidos, #proteina
Instance Method Summary collapse
- #aibc ⇒ Object
- #indiceg(other) ⇒ Object
-
#initialize(nombre, proteinas, glucidos, lipidos, vector) ⇒ IndiceGlucemico
constructor
Crea el vector con el contenido y llama a su clase padre.
-
#to_s ⇒ Object
Permite formatear la salida por pantalla.
Methods inherited from Comida
Constructor Details
#initialize(nombre, proteinas, glucidos, lipidos, vector) ⇒ IndiceGlucemico
Crea el vector con el contenido y llama a su clase padre.
9 10 11 12 |
# File 'lib/Alimento/IndiceGlucemico.rb', line 9 def initialize (nombre, proteinas, glucidos, lipidos, vector) super(nombre, proteinas, glucidos, lipidos) @dat = vector end |
Instance Attribute Details
#dat ⇒ Object (readonly)
Permite acceder a los atributos de la clase en forma de lectura.
6 7 8 |
# File 'lib/Alimento/IndiceGlucemico.rb', line 6 def dat @dat end |
Instance Method Details
#aibc ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/Alimento/IndiceGlucemico.rb', line 19 def aibc @dat.collect do |ind| ind.zip(1..ind.size).collect do |val, index| if ((index == ind.size) || (ind[index] < ind[0])) 0.0 else (((ind[index] - ind[0]) + (ind[index-1] - ind[0] )) / 2)*5 end end.reduce('+') end end |
#indiceg(other) ⇒ Object
31 32 33 |
# File 'lib/Alimento/IndiceGlucemico.rb', line 31 def indiceg(other) (((self.aibc).zip(other.aibc)).collect {|v1 , v2| ((v1 / v2) * 100)}.reduce('+')) / ((self.aibc).size) end |
#to_s ⇒ Object
Permite formatear la salida por pantalla.
15 16 17 |
# File 'lib/Alimento/IndiceGlucemico.rb', line 15 def to_s super.to_s + ", " + "#{dat}" end |