class Grupo
Public Class Methods
new(group_name)
click to toggle source
Constructor @param group_name as the name of the list @val as the first element of the list
Calls superclass method
Alimento::new
# File lib/pract/grupo.rb, line 8 def initialize (group_name) super(group_name, 0, 0, 0, []) @lista = Lista.new end
Public Instance Methods
delete(val)
click to toggle source
Remove an element called val
# File lib/pract/grupo.rb, line 28 def delete (val) @lista.remove(val) end
glucid_energy()
click to toggle source
@return the energy provided by glucids of all foods in the list
# File lib/pract/grupo.rb, line 51 def glucid_energy @glucid = 0 point = @lista.head while(@lista.tail != point) @glucid = @glucid + point.val.glucid_energy point = point.next end @glucid = @glucid + @lista.tail.val.glucid_energy return @glucid end
has_a(val)
click to toggle source
@return whether val is in the list or not
# File lib/pract/grupo.rb, line 32 def has_a(val) if(@lista.search(val) != 0) return true else return false end end
insert(val)
click to toggle source
Insert val to the last
# File lib/pract/grupo.rb, line 24 def insert (val) @lista.add_last(val) end
lipid_energy()
click to toggle source
@return the energy provided by lipids of all foods in the list
# File lib/pract/grupo.rb, line 62 def lipid_energy @lipid = 0 point = @lista.head while(@lista.tail != point) @lipid = @lipid + point.val.lipid_energy point = point.next end @lipid = @lipid + @lista.tail.val.lipid_energy return @lipid end
protein_energy()
click to toggle source
@return the energy provided by proteins of all foods in the list
# File lib/pract/grupo.rb, line 40 def protein_energy @protein = 0 point = @lista.head while(@lista.tail != point) @protein = @protein + point.val.protein_energy point = point.next end @protein = @protein + @lista.tail.val.protein_energy return @protein end
to_s()
click to toggle source
String format
# File lib/pract/grupo.rb, line 13 def to_s elements = @name + ":" elements << @lista.to_s #point = @lista.head #while(@lista.tail != point) # elements = elements + point.val.name + ", " # point = point.next #end #elements = elements + @lista.tail.val.name + " ]" end