Class: Grupo

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

Instance Attribute Summary

Attributes inherited from Alimento

#glucid, #lipid, #name, #protein

Instance Method Summary collapse

Methods inherited from Alimento

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

Constructor Details

#initialize(group_name, val) ⇒ 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, val)
	super(group_name, 0, 0, 0)
		@lista = Lista.new(val)
end

Instance Method Details

#delete(val) ⇒ Object

Remove an element called val



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

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



50
51
52
53
54
55
56
57
58
59
# File 'lib/pract/grupo.rb', line 50

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



31
32
33
34
35
36
37
# File 'lib/pract/grupo.rb', line 31

def has_a(val)
	if(@lista.search(val) != 0)
		return true
	else
		return false
	end
end

#insert(val) ⇒ Object

Insert val to the last



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

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



61
62
63
64
65
66
67
68
69
70
# File 'lib/pract/grupo.rb', line 61

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



39
40
41
42
43
44
45
46
47
48
# File 'lib/pract/grupo.rb', line 39

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
# File 'lib/pract/grupo.rb', line 13

def to_s
	elements = name + ":[ "
	point = @lista.head
	while(@lista.tail != point)
		elements = elements + point.val.name + ", "
		point = point.next 
	end
	elements = elements + @lista.tail.val.name + " ]"
end