Module: Ariel::NodeLike
- Included in:
- ExtractedNode, StructureNode
- Defined in:
- lib/ariel/node_like.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#add_child(node) ⇒ Object
Given a Node object and a name, adds a child to the array of children, setting its parent as the current node, as well as creating an accessor method matching that name.
- #each_descendant(include_self = false) ⇒ Object
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
4 5 6 |
# File 'lib/ariel/node_like.rb', line 4 def children @children end |
#meta ⇒ Object
Returns the value of attribute meta.
4 5 6 |
# File 'lib/ariel/node_like.rb', line 4 def @meta end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/ariel/node_like.rb', line 4 def parent @parent end |
Instance Method Details
#add_child(node) ⇒ Object
Given a Node object and a name, adds a child to the array of children, setting its parent as the current node, as well as creating an accessor method matching that name.
9 10 11 12 |
# File 'lib/ariel/node_like.rb', line 9 def add_child(node) @children[node..name]=node node.parent = self end |
#each_descendant(include_self = false) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ariel/node_like.rb', line 14 def each_descendant(include_self=false) if include_self node_queue=[self] else node_queue=self.children.values end until node_queue.empty? do node_queue.concat node_queue.first.children.values yield node_queue.shift end end |