Class: IndiceGlucemico

Inherits:
Comida
  • Object
show all
Defined in:
lib/Alimento/IndiceGlucemico.rb

Overview

Esta clase permite calcular el indice glucémico de un alimento. Hereda de la clase comida.

Instance Attribute Summary collapse

Attributes inherited from Comida

#comida, #glucidos, #lipidos, #proteina

Instance Method Summary collapse

Methods inherited from Comida

#<=>, #valorEnergetico

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

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

#aibcObject



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_sObject

Permite formatear la salida por pantalla.



15
16
17
# File 'lib/Alimento/IndiceGlucemico.rb', line 15

def to_s
    super.to_s +  ", " + "#{dat}"
end