Class: Katalyst::Content::HasTree::Builder

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/katalyst/content/has_tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



16
17
18
19
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 16

def initialize
  @depth    = 0
  @children = @tree = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



14
15
16
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14

def children
  @children
end

#currentObject

Returns the value of attribute current.



14
15
16
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14

def current
  @current
end

#depthObject

Returns the value of attribute depth.



14
15
16
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14

def depth
  @depth
end

#treeObject (readonly)

Returns the value of attribute tree.



14
15
16
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14

def tree
  @tree
end

Instance Method Details

#add(node) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 21

def add(node)
  if node.depth == depth
    node.parent = current
    children << node
    self
  elsif node.depth > depth
    push(children.last)
    add(node)
  else
    pop
    add(node)
  end
end