Module: NewspaperWorks::Ingest::NamedIssueMetadata
- Included in:
- IssueImages, PDFIssue
- Defined in:
- lib/newspaper_works/ingest/named_issue_metadata.rb
Overview
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.
Instance Method Summary collapse
-
#edition_number ⇒ Integer
Issue edition number.
-
#filename ⇒ String
Memoized filename from path:.
-
#lccn ⇒ Object
rubocop:disable Rails/Delegate.
-
#publication_date ⇒ String
Publication date stamp.
-
#title ⇒ Object
rubocop:enable Rails/Delegate.
- #validate_path ⇒ Object
Instance Method Details
#edition_number ⇒ Integer
Issue edition number
36 37 38 39 40 41 42 43 44 |
# 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 ⇒ String
Memoized filename from path:
12 13 14 15 |
# File 'lib/newspaper_works/ingest/named_issue_metadata.rb', line 12 def filename return @filename unless @filename.nil? @filename = File.basename(path) end |
#lccn ⇒ Object
rubocop:disable Rails/Delegate
47 48 49 |
# File 'lib/newspaper_works/ingest/named_issue_metadata.rb', line 47 def lccn publication.lccn end |
#publication_date ⇒ String
Publication date stamp
27 28 29 30 31 32 |
# 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 ⇒ Object
rubocop:enable Rails/Delegate
52 53 54 55 56 57 |
# 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 ⇒ Object
17 18 19 20 21 22 23 |
# 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 |