ruby-avm-library/lib/avm/node.rb

29 lines
633 B
Ruby

require 'delegate'
module AVM
# Delegate of Nokogiri::XML::Node which fixes XPath queries to use the correct namespace prefixes
class Node < DelegateClass(Nokogiri::XML::Node)
def initialize(xmp, node)
@xmp, @node = xmp, node
super(@node)
end
def at_xpath(path)
if node = @node.at_xpath(path, @xmp.namespaces)
self.class.new(@xmp, node)
else
nil
end
end
def search(path)
self.class.from_nodeset(@xmp, @node.search(path, @xmp.namespaces))
end
def self.from_nodeset(xmp, nodeset)
nodeset.collect { |node| new(xmp, node) }
end
end
end