11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/tallygem/tally.rb', line 11
def self.split(forest, recursive = true, depth = 1, task = nil)
set = Set.new
forest.each do |tree|
task = tree[:task] if tree.key? :task
if tree.key?(:subvotes) && !tree[:subvotes].empty?
tree[:subvotes].each do |sv|
sv[:task] ||= task unless task.nil?
sv[:depth] ||= depth
end
set.merge split(tree[:subvotes], recursive, depth + 1, task)
tree[:subvotes].clear unless recursive
end
set.add tree
end
set
end
|