Class: Alimento
Overview
Clase Alimento utilizada para las Prácticas de LPP
Direct Known Subclasses
Bebidas, Carnes, Frutas, Grasos, Hiperglucemicos, Lacteos, Pescados, Verduras
Instance Attribute Summary collapse
-
#gluci ⇒ Object
readonly
Returns the value of attribute gluci.
-
#grasa ⇒ Object
readonly
Returns the value of attribute grasa.
-
#nom ⇒ Object
readonly
Returns the value of attribute nom.
-
#prot ⇒ Object
readonly
Returns the value of attribute prot.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Este método muestra como se compara para que sea compatible con el modulo Comparable.
- #aibc_funcion ⇒ Object
-
#calorias ⇒ Object
Este método calcula el valor energético del alimento.
-
#initialize(nombre, protes, glucidos, gras, l) ⇒ Alimento
constructor
Este es el método para inicializar el contenido de los alimentos.
-
#to_s ⇒ Object
Este método da el formato para la salida por pantalla.
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
#gluci ⇒ Object (readonly)
Returns the value of attribute gluci.
15 16 17 |
# File 'lib/pract6/Alimento.rb', line 15 def gluci @gluci end |
#grasa ⇒ Object (readonly)
Returns the value of attribute grasa.
15 16 17 |
# File 'lib/pract6/Alimento.rb', line 15 def grasa @grasa end |
#nom ⇒ Object (readonly)
Returns the value of attribute nom.
15 16 17 |
# File 'lib/pract6/Alimento.rb', line 15 def nom @nom end |
#prot ⇒ Object (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_funcion ⇒ Object
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 |
#calorias ⇒ Object
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_s ⇒ Object
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 |