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.



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

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

Instance Method Details

#extract(path) ⇒ Object



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

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

#unescape!(path) ⇒ Object



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

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