Class: ContentTree
- Inherits:
-
Object
- Object
- ContentTree
- Defined in:
- lib/diml/document/content_tree.rb
Overview
Basic multi child Tree datastructure
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
ContentTree, Array<ContentTree>.
-
#content ⇒ Object
Returns the value of attribute content.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_child(child) ⇒ Object
- #has_children? ⇒ Boolean
-
#initialize ⇒ ContentTree
constructor
A new instance of ContentTree.
- #leaf? ⇒ Boolean
- #root! ⇒ Object
- #root? ⇒ Boolean
Constructor Details
#initialize ⇒ ContentTree
Returns a new instance of ContentTree.
13 14 15 16 17 |
# File 'lib/diml/document/content_tree.rb', line 13 def initialize @children = [] @parent = nil @content = nil end |
Instance Attribute Details
#children ⇒ Object (readonly)
ContentTree, Array<ContentTree>
11 12 13 |
# File 'lib/diml/document/content_tree.rb', line 11 def children @children end |
#content ⇒ Object
Returns the value of attribute content.
9 10 11 |
# File 'lib/diml/document/content_tree.rb', line 9 def content @content end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/diml/document/content_tree.rb', line 9 def parent @parent end |
Instance Method Details
#add_child(child) ⇒ Object
19 20 21 22 |
# File 'lib/diml/document/content_tree.rb', line 19 def add_child(child) child.parent = self @children << child end |
#has_children? ⇒ Boolean
32 33 34 |
# File 'lib/diml/document/content_tree.rb', line 32 def has_children? @children.size.positive? end |
#leaf? ⇒ Boolean
36 37 38 |
# File 'lib/diml/document/content_tree.rb', line 36 def leaf? !has_children? end |
#root! ⇒ Object
24 25 26 |
# File 'lib/diml/document/content_tree.rb', line 24 def root! @parent = nil end |
#root? ⇒ Boolean
28 29 30 |
# File 'lib/diml/document/content_tree.rb', line 28 def root? @parent.nil? end |