module NewspaperWorks::Ingest::PubFinder
mixin for find-or-create of publication, for use by various ingests
Constants
- COPY_FIELDS
- MULTI_VALUED
- WRAPPERS
Public Instance Methods
copy_publication_metadata(publication, metadata, lccn, title = nil)
click to toggle source
Copy publication metadata from authority lookup for LCCN @param publication [NewspaperTitle] @param metadata [NewspaperWorks::Ingest::PublicationInfo]
# File lib/newspaper_works/ingest/pub_finder.rb, line 43 def copy_publication_metadata(publication, metadata, lccn, title = nil) COPY_FIELDS.each do |name| value = metadata.send(name) next if value.nil? # wrapped value, if applicable: value = WRAPPERS[name].new(value) if WRAPPERS.include?(name) # value in array, if applicable: value = [value] if MULTI_VALUED.include?(name) publication.send("#{name}=", value) end # prefer locally-specified title to looked-up title: publication.title = [title] unless title.nil? # final fallback, nothing specified, title mandatory: use LCCN publication.title = [lccn] if publication.title.empty? end
create_publication(lccn, title = nil, opts = {})
click to toggle source
# File lib/newspaper_works/ingest/pub_finder.rb, line 59 def create_publication(lccn, title = nil, opts = {}) publication = NewspaperTitle.create info = NewspaperWorks::Ingest::PublicationInfo.new(lccn) copy_publication_metadata(publication, info, lccn, title) publication.lccn ||= lccn NewspaperWorks::Ingest.assign_administrative_metadata(publication, opts) publication.save! write_log( "Created NewspaperTitle work #{publication.id} for LCCN #{lccn}" ) publication end
find_or_create_publication_for_issue(issue, lccn, title, opts)
click to toggle source
# File lib/newspaper_works/ingest/pub_finder.rb, line 72 def find_or_create_publication_for_issue(issue, lccn, title, opts) publication = find_publication(lccn) unless publication.nil? write_log( "Found existing NewspaperTitle #{publication.id}, LCCN #{lccn}" ) end publication = create_publication(lccn, title, opts) if publication.nil? publication.members << issue publication.save! write_log( "Linked NewspaperIssue #{issue.id} to "\ "NewspaperTitle work #{publication.id}" ) end
find_publication(lccn)
click to toggle source
@param lccn [String] Library of Congress Control Number
of Publication
@return [NewspaperTitle, NilClass] publication or nil if not found
# File lib/newspaper_works/ingest/pub_finder.rb, line 36 def find_publication(lccn) NewspaperTitle.where(lccn: lccn).first end