Class: NewspaperWorks::Ingest::NDNP::BatchIngester

Inherits:
Object
  • Object
show all
Extended by:
FromCommand
Includes:
Logging
Defined in:
lib/newspaper_works/ingest/ndnp/batch_ingester.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FromCommand

batch_path, from_command, missing_path, normalize_path

Methods included from Logging

#configure_logger, #log, #logger, #message_format, #write_log

Constructor Details

#initialize(path, opts = {}) ⇒ BatchIngester

Returns a new instance of BatchIngester.

Parameters:

  • path (String)

    path to batch xml or directory

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

    global ingest options, to be passed to ingester components, may include administrative metadata.

Raises:

  • (IOError)


29
30
31
32
33
34
35
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 29

def initialize(path, opts = {})
  @path = self.class.normalize_path(path)
  raise IOError, "No batch file found: #{path}" if @path.empty?
  @opts = opts
  @batch = batch_enumerator
  configure_logger('ingest')
end

Instance Attribute Details

#batchObject

Returns the value of attribute batch.



12
13
14
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 12

def batch
  @batch
end

#optsObject

Returns the value of attribute opts.



12
13
14
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 12

def opts
  @opts
end

#pathObject

Returns the value of attribute path.



12
13
14
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 12

def path
  @path
end

Class Method Details

.normalize_path(path) ⇒ Object

normalize path, possibly from directory, to contained batch

manifest XML path:

Parameters:

  • path (String)


17
18
19
20
21
22
23
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 17

def self.normalize_path(path)
  return path unless File.directory?(path)
  batch_xml_path = Find.find(path).select do |f|
    f.downcase.end_with?('batch_1.xml', 'batch.xml')
  end
  batch_xml_path.find { |f| f.end_with?('_1.xml') } || batch_xml_path[0]
end

Instance Method Details

#ingestObject



37
38
39
40
41
42
43
44
45
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 37

def ingest
  write_log("Beginning NDNP batch ingest for #{@path}")
  batch.each do |issue|
    issue_ingester(issue).ingest
  end
  write_log(
    "NDNP batch ingest complete!"
  )
end