Module: HTree::Container::Loc

Included in:
Doc::Loc, Elem::Loc
Defined in:
lib/htree/loc.rb,
lib/htree/modules.rb

Instance Method Summary collapse

Instance Method Details

#childrenObject

children returns an array of child locations.



343
344
345
# File 'lib/htree/loc.rb', line 343

def children
  (0...@node.children.length).map {|i| get_subnode(i) }
end

#get_subnode_internal(index) ⇒ Object

get_subnode returns a location object which points to a subnode indexed by index.



317
318
319
320
321
322
323
324
325
# File 'lib/htree/loc.rb', line 317

def get_subnode_internal(index) # :nodoc:
  return @subloc[index] if @subloc.include? index
  node = @node.get_subnode(index)
  if node
    @subloc[index] = node.class::Loc.new(self, index, node)
  else
    @subloc[index] = HTree::Location.new(self, index, node)
  end
end

#subst_subnode(pairs) ⇒ Object

subst_subnode returns the location which refers the substituted tree.

loc.subst_subnode(pairs) -> loc

t = HTree('<a><b><c>')
l = t.make_loc.get_subnode(0, 0)
l = l.subst_subnode({0=>HTree('<z/>')})
pp t, l.top.to_node
# =>
#<HTree::Doc {elem <a> {elem <b> {emptyelem <c>}}}>
#<HTree::Doc {elem <a> {elem <b> {emptyelem <z>}}}>


338
339
340
# File 'lib/htree/loc.rb', line 338

def subst_subnode(pairs)
  self.subst_itself(@node.subst_subnode(pairs))
end