Class: Alexandria::BookProviders::SBNProvider

Inherits:
Z3950Provider show all
Includes:
GetText
Defined in:
lib/alexandria/book_providers/z3950.rb

Instance Attribute Summary

Attributes inherited from AbstractProvider

#fullname, #name, #prefs

Instance Method Summary collapse

Methods included from Logging

included, #log

Methods inherited from AbstractProvider

#<=>, abstract?, #abstract?, #action_name, #enabled, #reinitialize, #remove, #toggle_enabled, #transport, unabstract, #variable_name

Constructor Details

#initializeSBNProvider

Returns a new instance of SBNProvider.



330
331
332
333
334
335
336
337
338
339
# File 'lib/alexandria/book_providers/z3950.rb', line 330

def initialize
  super('SBN', 'Servizio Bibliotecario Nazionale (Italy)')
  prefs.variable_named('hostname').default_value = 'opac.sbn.it'
  prefs.variable_named('port').default_value = 3950
  prefs.variable_named('database').default_value = 'nopac'
  # supported 'USMARC', 'UNIMARC' , 'SUTRS'
  prefs.variable_named('record_syntax').default_value = 'USMARC'
  prefs.variable_named('charset').default_value = 'ISO-8859-1'
  prefs.read
end

Instance Method Details

#search(criterion, type) ⇒ Object

Raises:



341
342
343
344
345
346
347
348
349
350
351
# File 'lib/alexandria/book_providers/z3950.rb', line 341

def search(criterion, type)
  prefs.read

  isbn = type == SEARCH_BY_ISBN ? criterion : nil
  criterion = canonicalise_isbn_with_dashes(criterion)
  resultset = search_records(criterion, type, 0)
  log.debug { "total #{resultset.length}" }
  raise NoResultsError if resultset.length == 0
  results = books_from_marc(resultset, isbn)
  type == SEARCH_BY_ISBN ? results.first : results
end

#url(book) ⇒ Object



353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/alexandria/book_providers/z3950.rb', line 353

def url(book)
  'http://sbnonline.sbn.it/cgi-bin/zgw/BRIEF.pl?displayquery=' \
    '%253CB%253E%253Cfont%2520color%253D%2523000064%253E' \
    'Codice%2520ISBN%253C%2FB%253E%253C%2Ffont%253E%2520' \
    'contiene%2520%2522%2520%253CFONT%2520COLOR%253Dred%253E' +
    canonicalise_isbn_with_dashes(book.isbn) +
    '%253C%2FFONT%253E%2522&session=&zurl=opac&zquery=%281%3D7+4%3D2+2%3D3+5%3D100+6%3D1+3%3D3+%22' +
    canonicalise_isbn_with_dashes(book.isbn) +
    '%22%29&language=it&maxentries=10&target=0&position=1'
rescue => ex
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
  nil
end