Class: ContentTree

Inherits:
Object
  • Object
show all
Defined in:
lib/diml/document/content_tree.rb

Overview

Basic multi child Tree datastructure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContentTree

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

#childrenObject (readonly)

ContentTree, Array<ContentTree>



11
12
13
# File 'lib/diml/document/content_tree.rb', line 11

def children
  @children
end

#contentObject

Returns the value of attribute content.



9
10
11
# File 'lib/diml/document/content_tree.rb', line 9

def content
  @content
end

#parentObject

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

Returns:

  • (Boolean)


32
33
34
# File 'lib/diml/document/content_tree.rb', line 32

def has_children?
  @children.size.positive?
end

#leaf?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/diml/document/content_tree.rb', line 28

def root?
  @parent.nil?
end