Class: Gared::Aleph
- Inherits:
-
Object
- Object
- Gared::Aleph
- Defined in:
- lib/gared/aleph.rb
Instance Method Summary collapse
-
#initialize(host, port, database, syntax = 'USMARC') ⇒ Aleph
constructor
A new instance of Aleph.
- #query_person(person) ⇒ Object
- #query_persons(q) ⇒ Object
- #query_publication(publication) ⇒ Object
- #query_publications(q) ⇒ Object
- #query_publications_by_person(person, ctx = nil) ⇒ Object
Constructor Details
#initialize(host, port, database, syntax = 'USMARC') ⇒ Aleph
Returns a new instance of Aleph.
21 22 23 |
# File 'lib/gared/aleph.rb', line 21 def initialize(host, port, database, syntax = 'USMARC') @options = {host: host, port: port, database: database, syntax: syntax} end |
Instance Method Details
#query_person(person) ⇒ Object
27 28 |
# File 'lib/gared/aleph.rb', line 27 def query_person(person) end |
#query_persons(q) ⇒ Object
24 25 |
# File 'lib/gared/aleph.rb', line 24 def query_persons(q) end |
#query_publication(publication) ⇒ Object
33 34 |
# File 'lib/gared/aleph.rb', line 33 def query_publication(publication) end |
#query_publications(q) ⇒ Object
30 31 |
# File 'lib/gared/aleph.rb', line 30 def query_publications(q) end |
#query_publications_by_person(person, ctx = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 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 78 |
# File 'lib/gared/aleph.rb', line 36 def query_publications_by_person(person, ctx = nil) ZOOM::Connection.open(@options[:host], @options[:port]) do |conn| conn.database_name = @options[:database] # 'aleph.nli.org.il',9991 conn.preferred_record_syntax = @options[:syntax] rset = conn.search("@attr 1=1003 @attr 2=3 @attr 4=1 \"#{person}\"") rr = rset.records return nil if rr.nil? or rr.empty? ret = [] rr.each do |r| xml = Nokogiri::Slop(r.xml) xml.remove_namespaces! # keeps biting me :) # these scrapes are based on the National Library of Israel usage. No attempt to make it generic. :) p = Publication.new(ctx) begin p. = xml.xpath('//datafield[@tag=\'100\']/subfield[@code=\'a\']')[0].text # puts "author: #{p.author_line}" # DEBUG rescue nil end begin p.title = xml.xpath('//datafield[@tag=\'245\']/subfield[@code=\'a\']')[0].text # puts "title: #{p.title}" # DEBUG rescue nil end begin p.notes = xml.xpath('//datafield[@tag=\'500\']/subfield[@code=\'a\']').collect{|note| note.text}.join("\n") rescue nil end begin h = Holding.new h.source_id = xml.xpath('//datafield[@tag=\'090\']/subfield[@code=\'a\']')[0].text h.source_name = @options[:database] p.add_holding(h) ret << p rescue nil # ignore records with no holdings; they may be archival files or other non-publications end # end return ret end end |