Class: Alexandria::BookProviders::BLProvider

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

#initializeBLProvider

Returns a new instance of BLProvider.



246
247
248
249
250
251
252
253
254
# File 'lib/alexandria/book_providers/z3950.rb', line 246

def initialize
  super('BL', _('British Library'))
  prefs.variable_named('hostname').default_value = 'z3950cat.bl.uk'
  prefs.variable_named('port').default_value = 9909
  prefs.variable_named('database').default_value = 'BLAC'
  prefs.variable_named('record_syntax').default_value = 'SUTRS'
  prefs.variable_named('charset').default_value = 'ISO-8859-1'
  prefs.read
end

Instance Method Details

#search(criterion, type) ⇒ Object

Raises:



256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/alexandria/book_providers/z3950.rb', line 256

def search(criterion, type)
  return super unless prefs['record_syntax'] == 'SUTRS'

  prefs.read
  criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
  conn_count = type == SEARCH_BY_ISBN ? 1 : 10 # results to retrieve
  resultset = search_records(criterion, type, conn_count)
  log.debug { "total #{resultset.length}" }
  raise NoResultsError if resultset.length == 0
  results = books_from_sutrs(resultset)
  type == SEARCH_BY_ISBN ? results.first : results
end

#url(book) ⇒ Object



269
270
271
272
273
274
# File 'lib/alexandria/book_providers/z3950.rb', line 269

def url(book)
  'http://copac.ac.uk/openurl?isbn=' + Library.canonicalise_isbn(book.isbn)
rescue => ex
  log.warn { "Cannot create url for book #{book}; #{ex.message}" }
  nil
end