Class: WCID::ID

Inherits:
Object
  • Object
show all
Defined in:
lib/wcid/id.rb

Overview

A WCID::ID object is a single Identity record in WorldCat Identities.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ ID

Returns a new instance of ID.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wcid/id.rb', line 17

def initialize doc
  @record = doc.elements.to_a("searchRetrieveResponse/records/record")
  @identity = @record[0].elements['recordData/Identity']
  @pnkey = @identity.elements['pnkey'].text
  @lccn_record = @identity.elements['authorityInfo/lccn'].text
  @lccn = convert_lccn(@lccn_record)
  @identity = @record[0].elements['recordData/Identity'] 
  @type = @identity.attributes['type']
  @wiki_link = "http://en.wikipedia.org/wiki/#{(@identity.elements['authorityInfo/wikiLink']).text}" if @identity.elements['authorityInfo/wikiLink']
  @subfield_a = @identity.elements['authorityInfo/standardForm/suba'].text if @identity.elements['authorityInfo/standardForm/suba']
  @subfield_d = @identity.elements['authorityInfo/standardForm/subd'].text if @identity.elements['authorityInfo/standardForm/subd']
end

Instance Attribute Details

#lccnObject (readonly)

lccn = Library of Congress Control Number type = wiki_link = link to Wikipedia for this identity subfield_a = name subfield_d = dates associated with the name pnkey = each WorldCat Identities record is given a unique pnkey made up

the name and associated dates (and qualifier?). A pnkey is the most exact way to 
search WorldCat Identities.


16
17
18
# File 'lib/wcid/id.rb', line 16

def lccn
  @lccn
end

#pnkeyObject (readonly)

lccn = Library of Congress Control Number type = wiki_link = link to Wikipedia for this identity subfield_a = name subfield_d = dates associated with the name pnkey = each WorldCat Identities record is given a unique pnkey made up

the name and associated dates (and qualifier?). A pnkey is the most exact way to 
search WorldCat Identities.


16
17
18
# File 'lib/wcid/id.rb', line 16

def pnkey
  @pnkey
end

#subfield_aObject (readonly)

lccn = Library of Congress Control Number type = wiki_link = link to Wikipedia for this identity subfield_a = name subfield_d = dates associated with the name pnkey = each WorldCat Identities record is given a unique pnkey made up

the name and associated dates (and qualifier?). A pnkey is the most exact way to 
search WorldCat Identities.


16
17
18
# File 'lib/wcid/id.rb', line 16

def subfield_a
  @subfield_a
end

#subfield_dObject (readonly)

lccn = Library of Congress Control Number type = wiki_link = link to Wikipedia for this identity subfield_a = name subfield_d = dates associated with the name pnkey = each WorldCat Identities record is given a unique pnkey made up

the name and associated dates (and qualifier?). A pnkey is the most exact way to 
search WorldCat Identities.


16
17
18
# File 'lib/wcid/id.rb', line 16

def subfield_d
  @subfield_d
end

#typeObject (readonly)

lccn = Library of Congress Control Number type = wiki_link = link to Wikipedia for this identity subfield_a = name subfield_d = dates associated with the name pnkey = each WorldCat Identities record is given a unique pnkey made up

the name and associated dates (and qualifier?). A pnkey is the most exact way to 
search WorldCat Identities.


16
17
18
# File 'lib/wcid/id.rb', line 16

def type
  @type
end

lccn = Library of Congress Control Number type = wiki_link = link to Wikipedia for this identity subfield_a = name subfield_d = dates associated with the name pnkey = each WorldCat Identities record is given a unique pnkey made up

the name and associated dates (and qualifier?). A pnkey is the most exact way to 
search WorldCat Identities.


16
17
18
# File 'lib/wcid/id.rb', line 16

def wiki_link
  @wiki_link
end

Instance Method Details

#convert_lccn(lccn) ⇒ Object

A method to convert the Library of Congress Control Number as represented in the WorldCat Identities database into an LCCN subtable for searching the Linked Authority File.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wcid/id.rb', line 34

def convert_lccn(lccn)
  lccn.gsub!(' ', '')
  ll = lccn.length
  if lccn[ll - 6, 1] != '0'
    lccn = lccn[0, ll - 6] + "-" + lccn[ll - 6, 99]
  elsif lccn[ll - 5, 1] != '0'
    lccn = lccn[0, ll - 6] + "-" + lccn[ll - 5, 99]
  elsif lccn[ll - 4, 1] != '0'
    lccn = lccn[0, ll - 6] + "-" + lccn[ll - 4, 99]
  elsif lccn[ll - 3, 1] != '0'
    lccn = lccn[0, ll - 6] + "-" + lccn[ll - 3, 99]
  end
  lccn
end

#get_lc_authObject

Returns a MARC::Record representation of the associated LC authority record.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/wcid/id.rb', line 52

def get_lc_auth
  uri = URI.escape("http://errol.oclc.org/laf/#{self.lccn}.MarcXML")
  src = ''
  begin
    Timeout.timeout 20 do
      src = Net::HTTP.get(URI.parse("#{uri}"))
    end
    record = MARC::XMLReader.new(StringIO.new(string=src)).to_a[0]
  end
rescue Timeout::Error
  puts "The auth lookup timed out!"
  raise
rescue MARC::Exception => e
  puts "MARC exception: #{e}"
  raise
rescue REXML::ParseException
  puts "rexml error"
  raise
rescue EOFError
  puts "The service seems to be down!"
  raise "eof"
rescue Exception => e
  puts "some other type of exception"
  puts e
  raise
end