class NodeExtractor

Attributes

xml[R]

Public Class Methods

new(xml) click to toggle source
# File lib/src/extractor.rb, line 51
def initialize(xml)
  @xml = Nokogiri::XML(xml)
  @xml.remove_namespaces!
end

Public Instance Methods

extract(path) click to toggle source
# File lib/src/extractor.rb, line 56
def extract(path)
  xml.xpath(path)
rescue StandardError
  nil
end
unescape!(path) click to toggle source
# File lib/src/extractor.rb, line 62
def unescape!(path)
  node = extract(path)
  return if node.blank?

  first_node = node.first
  return if first_node.elements.present?

  first_node.children = Nokogiri::XML.fragment(first_node.content).children
end