Module: TrajectPlus::Macros::Xml

Defined in:
lib/traject_plus/macros/xml.rb

Overview

Macros for extracting MODS values from Nokogiri documents

Instance Method Summary collapse

Instance Method Details

#extract_xml(xpath, namespaces, options = {}) ⇒ Object

Parameters:

  • xpath (String)

    the xpath query expression

  • namespaces (Hash<String,String>)

    The namespaces for the xpath query

  • options (Hash) (defaults to: {})

    other options, may include :trim



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/traject_plus/macros/xml.rb', line 10

def extract_xml(xpath, namespaces, options = {})
  Deprecation.warn(self, "extract_xml is deprecated and will be removed in the next major release. Use the Traject 3 pipeline instead")

  lambda do |xml, accumulator, _context|
    result = xml.xpath(xpath, namespaces).map(&:text)
    unless options.empty?
      Deprecation.warn(self, "passing options to extract_xml is deprecated and will be removed in the next major release. Use the Traject 3 pipeline instead")
    end
    result = TrajectPlus::Extraction.apply_extraction_options(result, options)
    accumulator.concat(result)
  end
end