Class HTree::Location
In: htree/extract_text.rb
htree/loc.rb
htree/modules.rb
Parent: Object

Methods

extract_text   loc_list   make_loc   path   subst   subst_itself   top  

Included Modules

HTree

External Aliases

node -> to_node

Attributes

index  [R] 
node  [R] 
parent  [R] 

Public Instance methods

loc_list returns an array containing from location‘s root to itself.

  t = HTree('<a><b><c>')
  l = t.make_loc.get_subnode(0, 0, 0)
  pp l, l.loc_list
  # =>
  #<HTree::Location: doc()/a/b/c>
  [#<HTree::Location: doc()>,
   #<HTree::Location: doc()/a>,
   #<HTree::Location: doc()/a/b>,
   #<HTree::Location: doc()/a/b/c>]

return self.

path returns the path of the location.

  l = HTree.parse("<a><b>x</b><b/><a/>").make_loc
  l = l.get_subnode(0, 0, 0)
  p l.path # => "doc()/a/b[1]/text()"

subst substitutes several subtrees at once.

  t = HTree('<r><x/><y/><z/></r>')
  l = t.make_loc
  l2 = l.subst({
    l.root.get_subnode('k') => 'v',
    l.root.get_subnode(-1) => HTree('<a/>'),
    l.find_element('y') => nil,
    l.find_element('z').get_subnode(0) => HTree('<b/>'),
  })
  pp l2, l2.to_node
  # =>
  #<HTree::Doc::Loc: doc()>
  #<HTree::Doc
   {elem <r k="v"> {emptyelem <a>} {emptyelem <x>} {elem <z> {emptyelem <b>}}}>

subst_itself substitutes the node pointed by the location. It returns the location of substituted node.

 t1 = HTree('<a><b><c><d>')
 p t1
 l1 = t1.make_loc.get_subnode(0, 0, 0, 0)
 p l1
 l2 = l1.subst_itself(HTree('<z/>'))
 p l2
 t2 = l2.top.to_node
 p t2
 # =>
 #<HTree::Doc {elem <a> {elem <b> {elem <c> {emptyelem <d>}}}}>
 #<HTree::Location: doc()/a/b/c/d>
 #<HTree::Location: doc()/a/b/c/z>
 #<HTree::Doc {elem <a> {elem <b> {elem <c> {emptyelem <z>}}}}>

top returns the originator location.

  t = HTree('<a><b><c><d>')
  l = t.make_loc.get_subnode(0, 0, 0, 0)
  p l, l.top
  # =>
  #<HTree::Location: doc()/a/b/c/d>
  #<HTree::Location: doc()>

[Validate]