Class: NodeExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/src/extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ NodeExtractor

Returns a new instance of NodeExtractor.



54
55
56
57
# File 'lib/src/extractor.rb', line 54

def initialize(xml)
  @xml = Nokogiri::XML(xml)
  @xml.remove_namespaces!
end

Instance Method Details

#extract(path) ⇒ Object



59
60
61
62
63
# File 'lib/src/extractor.rb', line 59

def extract(path)
  xml.xpath(path)
rescue StandardError
  nil
end

#unescape!(path) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/src/extractor.rb', line 65

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