Class: Katalyst::Content::HasTree::Builder
- Inherits:
-
Object
- Object
- Katalyst::Content::HasTree::Builder
- Defined in:
- app/models/concerns/katalyst/content/has_tree.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#depth ⇒ Object
readonly
Returns the value of attribute depth.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #add(node) ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize ⇒ Builder
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
#children ⇒ Object
Returns the value of attribute children.
14 15 16 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14 def children @children end |
#current ⇒ Object
Returns the value of attribute current.
14 15 16 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14 def current @current end |
#depth ⇒ Object
Returns the value of attribute depth.
14 15 16 |
# File 'app/models/concerns/katalyst/content/has_tree.rb', line 14 def depth @depth end |
#tree ⇒ Object (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 |