class Alexandria::BookProviders::BLProvider
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/alexandria/book_providers/bl_provider.rb, line 27 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
Public Instance Methods
url(book)
click to toggle source
# File lib/alexandria/book_providers/bl_provider.rb, line 37 def url(book) "http://copac.ac.uk/openurl?isbn=" + Library.canonicalise_isbn(book.isbn) rescue StandardError => ex log.warn { "Cannot create url for book #{book}; #{ex.message}" } nil end
Private Instance Methods
books_from_sutrs(resultset)
click to toggle source
# File lib/alexandria/book_providers/bl_provider.rb, line 46 def books_from_sutrs(resultset) results = [] resultset[0..9].each do |record| text = record.render(prefs["charset"], "UTF-8") # File.open(',bl.marc', 'wb') {|f| f.write(text) } log.debug { text } title = isbn = publisher = publish_year = edition = nil authors = [] text.split("\n").each do |line| if (md = /^Title:\s+(.*)$/.match(line)) title = md[1].sub(/\.$/, "").squeeze(" ") elsif (md = /^(?:Added Person|ME-Personal) Name:\s+(.*),[^,]+$/.match(line)) authors << md[1] elsif (md = /^ISBN:\s+([\dXx]+)/.match(line)) isbn = Library.canonicalise_ean(md[1]) elsif (md = /^Imprint:.+:\s*(.+),/.match(line)) publisher = md[1] end end log.debug do msg = "Parsing SUTRS" msg += "\n title: #{title}" msg += "\n authors: #{authors.join(' and ')}" msg += "\n isbn: #{isbn}" msg += "\n publisher: #{publisher}" msg += "\n edition: #{edition}" msg end if title # and !authors.empty? book = Book.new(title, authors, isbn, (publisher || nil), (publish_year || nil), (edition || nil)) results << [book] end end results end