Class: Tempo::Model::Composite
- Inherits:
-
Base
- Object
- Base
- Tempo::Model::Composite
show all
- Defined in:
- lib/tempo/models/composite.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#id
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#delete, file, find, find_by_id, #freeze_dry, id_counter, ids, index, instances_have_attributes?, method_missing, read_from_file, respond_to?, run_find_by_method, run_sort_by_method, save_to_file
Constructor Details
#initialize(options = {}) ⇒ Composite
Returns a new instance of Composite.
40
41
42
43
44
|
# File 'lib/tempo/models/composite.rb', line 40
def initialize(options={})
super options
@parent = options.fetch(:parent, :root)
@children = options.fetch(:children, [])
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
12
13
14
|
# File 'lib/tempo/models/composite.rb', line 12
def children
@children
end
|
#parent ⇒ Object
Returns the value of attribute parent.
12
13
14
|
# File 'lib/tempo/models/composite.rb', line 12
def parent
@parent
end
|
Class Method Details
.delete(instance) ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/tempo/models/composite.rb', line 31
def delete(instance)
instance.children.each do |child_id|
child = find_by_id child_id
instance.remove_child child
end
super instance
end
|
.report_trees ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/tempo/models/composite.rb', line 16
def report_trees
report_array = "["
@index.each do |member|
if member.parent == :root
report_array += "["
report_array += member.report_branches
report_array += "],"
end
end
if report_array[-1] == ","
report_array = report_array[0..-2]
end
report_array += "]"
end
|
Instance Method Details
#<<(child) ⇒ Object
46
47
48
49
50
|
# File 'lib/tempo/models/composite.rb', line 46
def << child
@children << child.id unless @children.include? child.id
@children.sort!
child.parent = self.id
end
|
#remove_child(child) ⇒ Object
52
53
54
55
|
# File 'lib/tempo/models/composite.rb', line 52
def remove_child(child)
@children.delete child.id
child.parent = :root
end
|
#report_branches ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/tempo/models/composite.rb', line 57
def report_branches
report = self.id.to_s
child_report = ",["
@children.each do |c|
child = self.class.find_by_id c
child_report += "#{child.report_branches},"
end
if child_report == ",["
child_report = ""
else
child_report = child_report[0..-2] + "]"
end
report += child_report
end
|