class Framecurve::XMLBridge

This is a thin wrapper around the REXML library. We want FC to use nokogiri or libxml in the future, without modifying it's core functionality. Therefore we will use a thin layer on top of REXML and then migrate it to offer various backends

Public Class Methods

new() click to toggle source

TODO: detect for subclasses here

Calls superclass method
# File lib/framecurve/extractors/xml_bridge.rb, line 13
def self.new
  super
end

Public Instance Methods

document_from_io(io) click to toggle source

Return a wrapped document

# File lib/framecurve/extractors/xml_bridge.rb, line 18
def document_from_io(io)
  REXML::Document.new(io)
end
element_text(elem) click to toggle source
# File lib/framecurve/extractors/xml_bridge.rb, line 61
def element_text(elem)
  elem.text.to_s
end
parent(of_node, level = 1) click to toggle source

Get a Nth parent of the passed node

# File lib/framecurve/extractors/xml_bridge.rb, line 43
def parent(of_node, level = 1)
  ancestor = of_node
  until level.zero?
    ancestor = ancestor.parent
    level -= 1
  end
  return ancestor
end
parent_by_name(of_node, parent_name) click to toggle source
# File lib/framecurve/extractors/xml_bridge.rb, line 52
def parent_by_name(of_node, parent_name)
  ancestor = of_node
  until ancestor == ancestor.parent
    return ancestor if ancestor.node_name == parent_name
    ancestor == ancestor.parent
  end
  nil
end
xpath_each(from_root_node, path) click to toggle source

Yields each XPath-satisfying element to the passed block

# File lib/framecurve/extractors/xml_bridge.rb, line 33
def xpath_each(from_root_node, path)
  REXML::XPath.each(from_root_node, path, &Proc.new)
end
xpath_first(from_root_node, path) click to toggle source

Get the first node matching the XPath expression

# File lib/framecurve/extractors/xml_bridge.rb, line 23
def xpath_first(from_root_node, path)
  REXML::XPath.first(from_root_node, path)
end
xpath_first_text(from_root_node, path) click to toggle source

Get the text of the first node matching the XPath expression

# File lib/framecurve/extractors/xml_bridge.rb, line 28
def xpath_first_text(from_root_node, path)
  element_text(xpath_first(from_root_node, path))
end
xpath_of(node) click to toggle source

Returns the xpath to that specific node in the document

# File lib/framecurve/extractors/xml_bridge.rb, line 38
def xpath_of(node)
  node.xpath.to_s
end