class NewspaperWorks::Ingest::NDNP::IssueIngester

Constants

COPY_FIELDS

Attributes

issue[RW]
opts[RW]
target[RW]

Public Class Methods

new(issue, opts = {}) click to toggle source

@param issue [NewspaperWorks::Ingest::NDNP::IssueIngest]

source issue data

@param opts [Hash]

ingest options, e.g. administrative metadata
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 27
def initialize(issue, opts = {})
  @issue = issue
  @opts = opts
  @target = nil
  configure_logger('ingest')
end

Public Instance Methods

construct_issue() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 40
def construct_issue
  create_issue
  find_or_create_linked_publication
end
ingest() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 34
def ingest
  construct_issue
  ingest_pages
  NewspaperWorks::ComposeIssuePDFJob.perform_later(@target)
end
ingest_pages() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 45
def ingest_pages
  issue.each do |page|
    page_ingester(page).ingest
  end
end

Private Instance Methods

copy_issue_metadata() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 74
def copy_issue_metadata
  metadata = issue.metadata
  # set (required, plural) title from single value obtained from reel:
  @target.title = [issue_title]
  # copy all fields with singular (non-repeatable) values on both
  #   target NewspaperIssue object, and metadata source:
  COPY_FIELDS.each do |fieldname|
    @target.send("#{fieldname}=", metadata.send(fieldname.to_s))
  end
end
create_issue() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 85
def create_issue
  @target = NewspaperIssue.create
  copy_issue_metadata
  assign_administrative_metadata
  @target.save!
  write_log("Saved metadata to new NewspaperIssue #{@target.id}")
end
find_or_create_linked_publication() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 93
def find_or_create_linked_publication
  title = publication_title(issue)
  lccn = issue.metadata.lccn
  find_or_create_publication_for_issue(@target, lccn, title, @opts)
end
issue_title() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 70
def issue_title
  "#{publication_title(issue)}: #{publication_date}"
end
page_ingester(page_data) click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 53
def page_ingester(page_data)
  NewspaperWorks::Ingest::NDNP::PageIngester.new(
    page_data,
    @target,
    @opts
  )
end
publication_date() click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 61
def publication_date
  parsed = DateTime.iso8601(issue.metadata.publication_date)
  parsed.strftime('%B %-d, %Y')
end
publication_title(issue) click to toggle source
# File lib/newspaper_works/ingest/ndnp/issue_ingester.rb, line 66
def publication_title(issue)
  issue.metadata.publication_title.strip.split(/ \(/)[0]
end