module NewspaperWorks::Ingest::NamedIssueMetadata
Mixin for deducing issue metadata from path, publication info. precondition: consuming class has accessor for:
- `path`: full path to issue - `publication`: a `NewspaperWorks::Ingest::PublicationInfo object.
Public Instance Methods
edition_number()
click to toggle source
Issue edition number @return [Integer] number of issue edition
# File lib/newspaper_works/ingest/named_issue_metadata.rb, line 36 def edition_number # use file name minus file extension (if applicable, e.g. PDF): base = filename.split('.')[0..-2].join('.') # default for PDF or issue dir not specifying edition value in # name (before file extension, if applicable): return 1 if base.size < 10 # ...otherwise use explicitly provided edition number in filename base.slice(8, 2).to_i end
filename()
click to toggle source
Memoized filename from path: @return [String]
# File lib/newspaper_works/ingest/named_issue_metadata.rb, line 12 def filename return @filename unless @filename.nil? @filename = File.basename(path) end
lccn()
click to toggle source
rubocop:disable Rails/Delegate
# File lib/newspaper_works/ingest/named_issue_metadata.rb, line 47 def lccn publication.lccn end
publication_date()
click to toggle source
Publication date stamp @return [String] ISO 8601 date stamp
# File lib/newspaper_works/ingest/named_issue_metadata.rb, line 27 def publication_date year = filename.slice(0, 4).to_i month = filename.slice(4, 2).to_i day = filename.slice(6, 2).to_i DateTime.new(year, month, day).iso8601[0..9] end
title()
click to toggle source
rubocop:enable Rails/Delegate
# File lib/newspaper_works/ingest/named_issue_metadata.rb, line 52 def title title_date = DateTime.iso8601(publication_date).strftime('%B %-d, %Y') v = "#{publication.title}: #{title_date}" v = "#{v} (#{edition_number})" if edition_number.to_i > 1 [v] end
validate_path()
click to toggle source
# File lib/newspaper_works/ingest/named_issue_metadata.rb, line 17 def validate_path # expect path to exist: raise ArgumentError unless File.exist?(path) # `YYYYMMDDEE` with valid date digits, optional `EE` edition ptn = /^([0-9]{4})(1[012]|[0][1-9])(3[01]|[12][0-9]|0[1-9])([0-9]{2})?/ raise ArgumentError unless ptn.match(filename) end