class Alimento

Clase alimento que engloba a todas las otras pequeñas clases.

Attributes

gli[RW]
ind_gluc[RW]
lp[RW]
nombre[RW]
prt[RW]
valor_energ[RW]

Public Class Methods

new(nombre,proteina,glucido,lipido,tipo) click to toggle source
Calls superclass method Grupo::new
# File lib/pr06/alimento.rb, line 55
 def initialize(nombre,proteina,glucido,lipido,tipo)
    

super(tipo)

class Alimento


 
attr_accessor :nombre,:prt,:gli,:lp

 def initialize(nombre,proteina,glucido,lipido)
    


super(tipo)


 
    
@ind_gluc = nil  #variable para la glucosa
@nombre = nombre
@prt =proteina
@gl = glucido
@lp = lipido

  end
  
   def to_s

   

    s = "( "

    s << super.to_s        #encadenamiento (chaining)

    s << " #{@nombre}: #{@prt} g de proteina,#{@gl} g de glúcido,#{@lp} g de lipidos )"

    s

  end



    "(#{@nombre}: #{@prt} g de proteina,#{@gl} g de glúcido,#{@lp} g de lipidos )"

  end

  
    def get_prt
      @prt
  end 
  
  def get_nombre
      @nombre
  end
  
    def get_lp
      @lp
  end 
  
    def get_gl
      @gl
  end 
  
  
def valor_energetico
    
    @valor_energ= ( @prt * 4) + (@gl * 4) +(@lp * 9)
    
end


def <=>(other)


    @valor_energ=other.valor_energ
    
  end

def calculate_index(data, gluc)
        aibc = [[],[]]
        data.each do |x|
            aux = 0
            x.each_index do |a| 
                if (a  != 0) 
                    aux += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5
                end 
            end 
            aibc[0] << aux
        end
        gluc.each do |x|
            aux = 0
            x.each_index do |a| 
                if (a  != 0) 
                    aux += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5
                end 
            end 
            aibc[1] << aux
        end
        ig_index = []
        aibc[0].each_index { |x|  ig_index << ((aibc[0][x] / aibc[1][x]) * 100)}
        suma = 0
        ig_index.each{ |x| suma += x}
        @ind_gluc = (suma / ig_index.length)

    end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/pr06/alimento.rb, line 128
def <=>(other)


    @valor_energ=other.valor_energ
    
  end
calculate_index(data, gluc) click to toggle source
# File lib/pr06/alimento.rb, line 135
def calculate_index(data, gluc)
        aibc = [[],[]]
        data.each do |x|
            aux = 0
            x.each_index do |a| 
                if (a  != 0) 
                    aux += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5
                end 
            end 
            aibc[0] << aux
        end
        gluc.each do |x|
            aux = 0
            x.each_index do |a| 
                if (a  != 0) 
                    aux += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5
                end 
            end 
            aibc[1] << aux
        end
        ig_index = []
        aibc[0].each_index { |x|  ig_index << ((aibc[0][x] / aibc[1][x]) * 100)}
        suma = 0
        ig_index.each{ |x| suma += x}
        @ind_gluc = (suma / ig_index.length)

    end
get_gl() click to toggle source
# File lib/pr06/alimento.rb, line 116
  def get_gl
    @gl
end
get_lp() click to toggle source
# File lib/pr06/alimento.rb, line 112
  def get_lp
    @lp
end
get_nombre() click to toggle source
# File lib/pr06/alimento.rb, line 108
def get_nombre
    @nombre
end
get_prt() click to toggle source
# File lib/pr06/alimento.rb, line 104
  def get_prt
    @prt
end
valor_energetico() click to toggle source
# File lib/pr06/alimento.rb, line 121
def valor_energetico
    
    @valor_energ= ( @prt * 4) + (@gl * 4) +(@lp * 9)
    
end