Class: NewspaperWorks::Ingest::NDNP::BatchIngester
- Inherits:
-
Object
- Object
- NewspaperWorks::Ingest::NDNP::BatchIngester
- Extended by:
- FromCommand
- Includes:
- Logging
- Defined in:
- lib/newspaper_works/ingest/ndnp/batch_ingester.rb
Instance Attribute Summary collapse
-
#batch ⇒ Object
Returns the value of attribute batch.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
-
.normalize_path(path) ⇒ Object
normalize path, possibly from directory, to contained batch manifest XML path:.
Instance Method Summary collapse
- #ingest ⇒ Object
-
#initialize(path, opts = {}) ⇒ BatchIngester
constructor
A new instance of BatchIngester.
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.
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
#batch ⇒ Object
Returns the value of attribute batch.
12 13 14 |
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 12 def batch @batch end |
#opts ⇒ Object
Returns the value of attribute opts.
12 13 14 |
# File 'lib/newspaper_works/ingest/ndnp/batch_ingester.rb', line 12 def opts @opts end |
#path ⇒ Object
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:
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
#ingest ⇒ Object
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 |