Class: NewspaperWorks::Ingest::ChronAmPublicationInfo

Inherits:
BasePublicationInfo show all
Defined in:
lib/newspaper_works/ingest/chronam_publication_info.rb

Overview

Publication info from ChronAm as remote authority for metadata

Constant Summary collapse

XML_NS =
{
  dcterms: 'http://purl.org/dc/terms/',
  frbr: 'http://purl.org/vocab/frbr/core#',
  owl: 'http://www.w3.org/2002/07/owl#',
  rda: 'http://rdvocab.info/elements/',
  rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  rdfs: 'http://www.w3.org/2000/01/rdf-schema#'
}.freeze
BASE_URL =
'https://chroniclingamerica.loc.gov/lccn'.freeze

Instance Attribute Summary collapse

Attributes inherited from BasePublicationInfo

#lccn

Instance Method Summary collapse

Methods inherited from BasePublicationInfo

#oclc_prefixed, #place_name_from_title

Constructor Details

#initialize(lccn) ⇒ ChronAmPublicationInfo

Returns a new instance of ChronAmPublicationInfo.



21
22
23
24
25
26
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 21

def initialize(lccn)
  # true until loaded
  @empty = true
  super(lccn)
  @issn = nil # chronam doesn't have this
end

Instance Attribute Details

#issnObject

Returns the value of attribute issn.



8
9
10
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 8

def issn
  @issn
end

#languageObject

Returns the value of attribute language.



8
9
10
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 8

def language
  @language
end

#place_nameObject

Returns the value of attribute place_name.



8
9
10
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 8

def place_name
  @place_name
end

#place_of_publicationObject

Returns the value of attribute place_of_publication.



8
9
10
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 8

def place_of_publication
  @place_of_publication
end

#titleObject

Returns the value of attribute title.



8
9
10
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 8

def title
  @title
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 28

def empty?
  @empty
end

#inspectObject



32
33
34
35
36
37
38
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 32

def inspect
  format(
    "<#{self.class}:0x000000000%<oid>x " \
      "\tlccn: '#{@lccn}'>",
    oid: object_id << 1
  )
end

#loadObject



53
54
55
56
57
58
59
60
61
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 53

def load
  resp = NewspaperWorks::ResourceFetcher.get url
  return if resp['status'] == 404
  @doc = Nokogiri.XML(resp['body'])
  @title = normalize_title(find('//dcterms:title').first.text)
  @language = iso_language_for(find('//dcterms:language').first.text)
  @empty = false
  load_place
end

#load_placeObject



40
41
42
43
44
45
46
47
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 40

def load_place
  place_match = find('//rda:placeOfPublication')
  return if place_match.nil?
  @place_name = place_match.first.text
  @place_of_publication = NewspaperWorks::Ingest.geonames_place_uri(
    @place_name
  )
end

#oclcnumObject



63
64
65
66
67
68
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 63

def oclcnum
  key = 'info:oclcnum'
  selected = sameas_resources.select { |v| v.text.start_with?(key) }
  return if selected.empty?
  oclc_prefixed(selected[0].text.split('/')[1])
end

#preceded_byObject



70
71
72
73
74
75
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 70

def preceded_by
  return if empty?
  found = find('//frbr:successorOf/@rdf:resource').first
  return if found.nil?
  normalize_related(found.text)
end

#succeeded_byObject



77
78
79
80
81
82
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 77

def succeeded_by
  return if empty?
  found = find('//frbr:successor/@rdf:resource').first
  return if found.nil?
  normalize_related(found.text)
end

#urlObject



49
50
51
# File 'lib/newspaper_works/ingest/chronam_publication_info.rb', line 49

def url
  "#{BASE_URL}/#{@lccn}.rdf"
end