class Hyrax::Ingest::Fetcher::XMLFile

Attributes

default[R]
fetched_value[R]
filename[R]
xpath[R]

Public Class Methods

new(options={}) click to toggle source
Calls superclass method Hyrax::Ingest::Fetcher::Base::new
# File lib/hyrax/ingest/fetcher/xml_file.rb, line 17
def initialize(options={})
  raise ArgumentError, "Required option :filename is missing" unless options.key?(:filename)
  raise ArgumentError, "Required option :xpath is missing" unless options.key?(:xpath)
  @filename = options[:filename]
  @xpath = options[:xpath]
  @default = options[:default] || []
  super
end

Public Instance Methods

fetch() click to toggle source

Overrides Hyrax::Ingest::Fetcher::Base#fetch @return [String] The value fetched from the XML file

# File lib/hyrax/ingest/fetcher/xml_file.rb, line 28
def fetch
  @fetched_value ||= begin
    fetched_from_xml = noko.xpath(xpath).map(&:text)
    fetched_from_xml.empty? ? default : fetched_from_xml
  end
end

Protected Instance Methods

noko() click to toggle source
# File lib/hyrax/ingest/fetcher/xml_file.rb, line 45
def noko
  @noko ||= Nokogiri::XML(sip.read_file(filename)).tap do |n|
    # TODO: allow using namespaces instead of blindly removing them.
    n.remove_namespaces!
  end
end
report_missing_required_value() click to toggle source

Overrides Hyrax::Ingest::Fetcher::Base#report_missing_required_value, passing filename and xpath inforamtion. The report summary has specific logic to look for these.

# File lib/hyrax/ingest/fetcher/xml_file.rb, line 41
def report_missing_required_value
  super(filename: filename, xpath: xpath)
end