Class: Alimento

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/pract6/Alimento.rb

Overview

Clase Alimento utilizada para las Prácticas de LPP

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nombre, protes, glucidos, gras, l) ⇒ Alimento

Este es el método para inicializar el contenido de los alimentos



18
19
20
21
22
23
24
25
# File 'lib/pract6/Alimento.rb', line 18

def initialize(nombre,protes,glucidos,gras,l)
  @nom = nombre
  @prot= protes
  @gluci = glucidos
  @grasa = gras
  @lista  = l
  @aibc = List.new()
end

Instance Attribute Details

#gluciObject (readonly)

Returns the value of attribute gluci.



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

def gluci
  @gluci
end

#grasaObject (readonly)

Returns the value of attribute grasa.



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

def grasa
  @grasa
end

#nomObject (readonly)

Returns the value of attribute nom.



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

def nom
  @nom
end

#protObject (readonly)

Returns the value of attribute prot.



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

def prot
  @prot
end

Instance Method Details

#<=>(other) ⇒ Object

Este método muestra como se compara para que sea compatible con el modulo Comparable



37
38
39
# File 'lib/pract6/Alimento.rb', line 37

def <=>(other)
  self.calorias <=> other.calorias
end

#aibc_funcionObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pract6/Alimento.rb', line 41

def aibc_funcion

  @lista.collect do |i|
    nodo = Node.new()
    nodo.value = 0
        i.value.collect do |j|
          if (j != i.value.head)
            nodo.value+= ((j.value - i.value.tail.value) + (j.prev.value - i.value.tail.value))/2*5
          end
        end
        @aibc.insert(nodo)
  end
  return @aibc
end

#caloriasObject

Este método calcula el valor energético del alimento



32
33
34
# File 'lib/pract6/Alimento.rb', line 32

def calorias
  @prot*4 + @gluci*4 + @grasa*9
end

#to_sObject

Este método da el formato para la salida por pantalla



27
28
29
# File 'lib/pract6/Alimento.rb', line 27

def to_s
  "#{@nom}    \t#{@prot}\t#{@gluci}\t#{@grasa}"
end