Module: HierarchyWithLevel

Included in:
ActiveRecord::Base
Defined in:
lib/hierarchy/hierarchy_with_level.rb

Instance Method Summary collapse

Instance Method Details

#hchildren(result_set) ⇒ Object



16
17
18
19
# File 'lib/hierarchy/hierarchy_with_level.rb', line 16

def hchildren(result_set)
  result_group = group_result_set(result_set)
  self.hchildren_structure(result_set,result_group)
end

#hchildren_ids(result_set) ⇒ Object



21
22
23
24
# File 'lib/hierarchy/hierarchy_with_level.rb', line 21

def hchildren_ids(result_set)
  result_group = group_result_set(result_set)
  self.hchildren_structure_ids(result_set,result_group)
end

#hchildren_structure(result_set, result_group) ⇒ Object



26
27
28
# File 'lib/hierarchy/hierarchy_with_level.rb', line 26

def hchildren_structure(result_set,result_group)
    result_group[self.id] unless presence_check(result_group[self.id]) 
end

#hchildren_structure_ids(result_set, result_group) ⇒ Object



30
31
32
# File 'lib/hierarchy/hierarchy_with_level.rb', line 30

def hchildren_structure_ids(result_set,result_group)
    result_group[self.id].map(&:id) unless presence_check(result_group[self.id]) 
end

#hierarchy_level(result_set, depth = 0) ⇒ Object



3
4
5
6
# File 'lib/hierarchy/hierarchy_with_level.rb', line 3

def hierarchy_level(result_set,depth = 0)
  result_group = group_result_set(result_set)
  level_check(depth) ? self.tree_structure_level(result_set,result_group) : self.tree_structure_level_depth(result_set,result_group,depth.to_i)
end

#tree_structure_level(result_set, result_group, increment = 1) ⇒ Object



8
9
10
# File 'lib/hierarchy/hierarchy_with_level.rb', line 8

def tree_structure_level(result_set,result_group,increment = 1)
  presence_check(result_group[self.id]) ? self.attributes.merge({:level => increment}) : self.attributes.merge({:level => increment, :children => result_group[self.id].map{|x| x.tree_structure_level(result_set,result_group,increment + 1)}}) 
end

#tree_structure_level_depth(result_set, result_group, depth, increment = 1) ⇒ Object



12
13
14
# File 'lib/hierarchy/hierarchy_with_level.rb', line 12

def tree_structure_level_depth(result_set,result_group,depth,increment = 1)
  presence_check(result_group[self.id]) ? self.attributes.merge({:level => increment}) : self.attributes.merge({:level => increment, :children => result_group[self.id].map{|x| x.tree_structure_level_depth(result_set,result_group,depth,increment + 1)}}) unless compare(increment,depth)
end