Sha256: 2c611145ae92cd129211b53b33a5ff706b548fca4334a338e7dc297f717d7bed

Contents?: true

Size: 1.19 KB

Versions: 2

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

# This file is part of Alexandria.
#
# See the file README.md for authorship and licensing information.

require "alexandria/book_providers/z3950_provider"

module Alexandria
  class BookProviders
    class LOCProvider < Z3950Provider
      # http://en.wikipedia.org/wiki/Library_of_Congress
      unabstract

      include GetText
      GetText.bindtextdomain(Alexandria::TEXTDOMAIN, charset: "UTF-8")

      def initialize
        super("LOC", _("Library of Congress (Usa)"))
        prefs.variable_named("hostname").default_value = "z3950.loc.gov"
        prefs.variable_named("port").default_value = 7090
        prefs.variable_named("database").default_value = "Voyager"
        prefs.variable_named("record_syntax").default_value = "USMARC"
        prefs.variable_named("charset").default_value = "ISO-8859-1"
        prefs.read
      end

      def url(book)
        isbn = Library.canonicalise_isbn(book.isbn)
        "http://catalog.loc.gov/cgi-bin/Pwebrecon.cgi?" \
          "DB=local&CNT=25+records+per+page&CMD=isbn+#{isbn}"
      rescue StandardError => ex
        log.warn { "Cannot create url for book #{book}; #{ex.message}" }
        nil
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
alexandria-book-collection-manager-0.7.10 lib/alexandria/book_providers/loc_provider.rb
alexandria-book-collection-manager-0.7.9 lib/alexandria/book_providers/loc_provider.rb