class NewspaperWorks::Ingest::NDNP::BatchIngester
Attributes
batch[RW]
opts[RW]
path[RW]
Public Class Methods
new(path, opts = {})
click to toggle source
@param path [String] path to batch xml or directory @param opts [Hash]
global ingest options, to be passed to ingester components, may include administrative metadata.
# 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
normalize_path(path)
click to toggle source
normalize path, possibly from directory, to contained batch
manifest XML path:
@param path [String]
# 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
Public Instance Methods
ingest()
click to toggle source
# 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
Private Instance Methods
batch_enumerator()
click to toggle source
Return BatchIngest object as enumerable of issues:
# File lib/newspaper_works/ingest/ndnp/batch_ingester.rb, line 50 def batch_enumerator NewspaperWorks::Ingest::NDNP::BatchXMLIngest.new(path) end
issue_ingester(issue)
click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_ingester.rb, line 54 def issue_ingester(issue) NewspaperWorks::Ingest::NDNP::IssueIngester.new(issue, @opts) end
normalize_date(v)
click to toggle source
# File lib/newspaper_works/ingest/ndnp/batch_ingester.rb, line 58 def normalize_date(v) (v.is_a?(String) ? Date.parse(v) : v).to_s end