Module: Ariel::NodeLike

Included in:
ExtractedNode, StructureNode
Defined in:
lib/ariel/node_like.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/ariel/node_like.rb', line 4

def children
  @children
end

#metaObject

Returns the value of attribute meta.



4
5
6
# File 'lib/ariel/node_like.rb', line 4

def meta
  @meta
end

#parentObject

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.meta.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