Class: Grupo
Instance Attribute Summary
Attributes inherited from Alimento
#glucid, #lipid, #name, #protein
Instance Method Summary collapse
-
#delete(val) ⇒ Object
Remove an element called val.
-
#glucid_energy ⇒ Object
The energy provided by glucids of all foods in the list.
-
#has_a(val) ⇒ Object
Whether val is in the list or not.
-
#initialize(group_name, val) ⇒ Grupo
constructor
Constructor.
-
#insert(val) ⇒ Object
Insert val to the last.
-
#lipid_energy ⇒ Object
The energy provided by lipids of all foods in the list.
-
#protein_energy ⇒ Object
The energy provided by proteins of all foods in the list.
-
#to_s ⇒ Object
String format.
Methods inherited from Alimento
#<=>, #==, #energy, #show_energy
Constructor Details
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_energy ⇒ Object
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
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_energy ⇒ Object
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_energy ⇒ Object
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_s ⇒ Object
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 |