module NewspaperWorks::Ingest::BatchIngestHelper

mixin module for common batch ingest steps

Public Instance Methods

attach_file(work, path) click to toggle source
# File lib/newspaper_works/ingest/batch_ingest_helper.rb, line 37
def attach_file(work, path)
  attachment = NewspaperWorks::Data::WorkFiles.of(work)
  attachment.assign(path)
  attachment.commit!
end
copy_issue_metadata(source, target) click to toggle source
# File lib/newspaper_works/ingest/batch_ingest_helper.rb, line 30
def copy_issue_metadata(source, target)
  target.title = issue_title(source)
  target.lccn = source.lccn
  target.publication_date = source.publication_date
  target.edition_number = source.edition_number
end
detect_media(path) click to toggle source
# File lib/newspaper_works/ingest/batch_ingest_helper.rb, line 7
def detect_media(path)
  result = 'pdf' # default
  Find.find(path) do |p|
    result = 'image' if p.end_with?('jp2') || /TIF[F]?$/i.match(p)
  end
  result
end
issue_title(issue_data) click to toggle source
# File lib/newspaper_works/ingest/batch_ingest_helper.rb, line 26
def issue_title(issue_data)
  issue_data.title
end
lccn_from_path(path) click to toggle source
# File lib/newspaper_works/ingest/batch_ingest_helper.rb, line 15
def lccn_from_path(path)
  File.basename(path)
end
normalize_lccn(v) click to toggle source
# File lib/newspaper_works/ingest/batch_ingest_helper.rb, line 19
def normalize_lccn(v)
  p = /^[A-Za-z]{0,3}[0-9]{8}([0-9]{2})?$/
  v = v.gsub(/\s+/, '').downcase.slice(0, 13)
  raise ArgumentError, "LCCN appears invalid: #{v}" unless p.match(v)
  v
end