Class: Grupo

Inherits:
Alimento show all
Defined in:
lib/pract/grupo.rb

Direct Known Subclasses

Plate

Instance Attribute Summary

Attributes inherited from Alimento

#glucid, #glucose, #lipid, #name, #protein

Instance Method Summary collapse

Methods inherited from Alimento

#<=>, #==, #aibc, #energy, #show_energy

Constructor Details

#initialize(group_name) ⇒ Grupo

Constructor

Parameters:

  • group_name

    as the name of the list



8
9
10
11
# File 'lib/pract/grupo.rb', line 8

def initialize (group_name)
  super(group_name, 0, 0, 0, [])
    @lista = Lista.new
end

Instance Method Details

#delete(val) ⇒ Object

Remove an element called val



28
29
30
# File 'lib/pract/grupo.rb', line 28

def delete (val)
  @lista.remove(val)
end

#glucid_energyObject

Returns the energy provided by glucids of all foods in the list.

Returns:

  • the energy provided by glucids of all foods in the list



51
52
53
54
55
56
57
58
59
60
# 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) ⇒ Object

Returns whether val is in the list or not.

Returns:

  • whether val is in the list or not



32
33
34
35
36
37
38
# 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) ⇒ Object

Insert val to the last



24
25
26
# File 'lib/pract/grupo.rb', line 24

def insert (val)
  @lista.add_last(val)
end

#lipid_energyObject

Returns the energy provided by lipids of all foods in the list.

Returns:

  • the energy provided by lipids of all foods in the list



62
63
64
65
66
67
68
69
70
71
# 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_energyObject

Returns the energy provided by proteins of all foods in the list.

Returns:

  • the energy provided by proteins of all foods in the list



40
41
42
43
44
45
46
47
48
49
# 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_sObject

String format



13
14
15
16
17
18
19
20
21
22
# 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