Class: Alimento

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/nutrientes/alimento.rb

Overview

Esta clase representa a un alimento

Author:

  • Miguel JimĂ©nez Gomis

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, p, g, l) ⇒ Alimento

Returns a new instance of Alimento



10
11
12
13
14
15
16
# File 'lib/nutrientes/alimento.rb', line 10

def initialize(nombre, p, g, l)
	@nombre = nombre
	@proteinas = p
	@glucidos = g
	@lipidos = l
	@indexglucosa = nil
end

Instance Attribute Details

#glucidosObject (readonly)

Permite la lectura de estas variables



8
9
10
# File 'lib/nutrientes/alimento.rb', line 8

def glucidos
  @glucidos
end

#indexglucosaObject (readonly)

Permite la lectura de estas variables



8
9
10
# File 'lib/nutrientes/alimento.rb', line 8

def indexglucosa
  @indexglucosa
end

#lipidosObject (readonly)

Permite la lectura de estas variables



8
9
10
# File 'lib/nutrientes/alimento.rb', line 8

def lipidos
  @lipidos
end

#nombreObject (readonly)

Permite la lectura de estas variables



8
9
10
# File 'lib/nutrientes/alimento.rb', line 8

def nombre
  @nombre
end

#proteinasObject (readonly)

Permite la lectura de estas variables



8
9
10
# File 'lib/nutrientes/alimento.rb', line 8

def proteinas
  @proteinas
end

Instance Method Details

#<=>(anOther) ⇒ bool

Operador <=> para el modulo Comparable

Parameters:

  • anOther (Alimento)

    Otro objeto de tipo alimento

Returns:

  • (bool)

    -1 menor, 0 igual, 1 mayor.



66
67
68
# File 'lib/nutrientes/alimento.rb', line 66

def <=>(anOther)
	return self.v_energetico <=> anOther.v_energetico
end

#calculate_index(data, glucosa) ⇒ Object

Calcula el indice glucemico de un alimento

Parameters:

  • data (Array)

    Vector con los datos glucemicos de los alimentos

  • glucosa (Array)

    Vector con los datos de la glucosa



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/nutrientes/alimento.rb', line 22

def calculate_index(data, glucosa)
	aibc = []
	aibc_gluc = []
	data.each do |x|
		t = 0
		x.each_index do |a| 
			if (a  != 0) 
				t += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5  
			end 
		end 
		aibc << t
	end
	glucosa.each do |x|
		t = 0
		x.each_index do |a| 
			if (a  != 0) 
				t += (((x[a] - x[0]) + (x[a - 1] - x[0])) /2)*5
			end 
		end 
		aibc_gluc << t
	end
	igind = []
	aibc.each_index { |x|  igind << ((aibc[x] / aibc_gluc[x]) * 100)}
	
	suma = 0
	igind.each{ |x| suma += x}
	@indexglucosa = (suma / igind.length)
end

#to_sObject

Converts the object into a string



52
53
54
# File 'lib/nutrientes/alimento.rb', line 52

def to_s()
	return "Nombre: #{@nombre}, Proteinas: #{@proteinas}gr, GlĂșcidos: #{@glucidos}gr, Lipidos: #{@lipidos}gr"
end

#v_energeticoInteger

Este metodo calcula el valor energetico de un alimento

Returns:

  • (Integer)

    El calculo del valor energetico.



58
59
60
# File 'lib/nutrientes/alimento.rb', line 58

def v_energetico()
	return (@proteinas * 4 + @glucidos * 4 + @lipidos * 9)
end