Class: Hyrax::Ingest::Fetcher::XMLFile

Inherits:
Base
  • Object
show all
Includes:
HasSIP
Defined in:
lib/hyrax/ingest/fetcher/xml_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HasSIP

#sip, #sip=

Methods inherited from Base

#required?

Methods included from HasLogger

config, #logger, #logger=

Methods included from HasReport

#report, #report=

Constructor Details

#initialize(options = {}) ⇒ XMLFile

Returns a new instance of XMLFile.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
# 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

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



13
14
15
# File 'lib/hyrax/ingest/fetcher/xml_file.rb', line 13

def default
  @default
end

#fetched_valueObject (readonly)

Returns the value of attribute fetched_value.



13
14
15
# File 'lib/hyrax/ingest/fetcher/xml_file.rb', line 13

def fetched_value
  @fetched_value
end

#filenameObject (readonly)

Returns the value of attribute filename.



13
14
15
# File 'lib/hyrax/ingest/fetcher/xml_file.rb', line 13

def filename
  @filename
end

#xpathObject (readonly)

Returns the value of attribute xpath.



13
14
15
# File 'lib/hyrax/ingest/fetcher/xml_file.rb', line 13

def xpath
  @xpath
end

Instance Method Details

#fetchString

Overrides Hyrax::Ingest::Fetcher::Base#fetch

Returns:

  • (String)

    The value fetched from the XML file



28
29
30
31
32
33
# 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