Module: LibXML::XML

Defined in:
lib/rmtools/xml/libxml.rb,
lib/rmtools/xml/finders.rb,
lib/rmtools/xml/document.rb,
lib/rmtools/xml/node.rb

Defined Under Namespace

Modules: XPath Classes: Attributes, Document, Node

Constant Summary collapse

DefaultNS =
{}
FindByIndex =
lambda {|node, ns, ss|
  index = ss.matched[1..-2]
  if index.index('.')
    range = Range(*index.split('..').to_is)
    node = node.is(Array) ?
      node.sum([]) {|n| n.__find(nil, ns, ss).to_a[range]} : 
                      node.__find(nil, ns, ss).to_a[range]
  else
    node = node.is(Array) ?
      node.map {|n| n.__find(nil, ns, ss)[index.to_i]}.compact : 
                      node.__find(nil, ns, ss)[index.to_i]
  end
  node.is(Array) && node.size < 2 ? node[0] : node
}
FindByProc =
lambda {|node, ns, ss|
  str_to_eval = ss.matched[1..-2]
  block = eval "lambda {|_| #{str_to_eval['_'] ? '' : str_to_eval[0] == '[' ? '_' : '_.'}#{str_to_eval}}"
  node = node.is(Array) ?
    node.sum([]) {|n| n.__find(nil, ns, ss).select(&block).to_a} : 
                    node.__find(nil, ns, ss).select(&block)
  node.is(Array) && node.size < 2 ? node[0] : node
}