Class: Alexandria::BookProviders::WorldCatProvider
- Inherits:
-
WebsiteBasedProvider
- Object
- AbstractProvider
- GenericProvider
- WebsiteBasedProvider
- Alexandria::BookProviders::WorldCatProvider
- Includes:
- Logging
- Defined in:
- lib/alexandria/book_providers/worldcat.rb
Constant Summary collapse
- SITE =
"https://www.worldcat.org"
- BASE_SEARCH_URL =
type, term
"#{SITE}/search?q=%s%s&qt=advanced"
Instance Attribute Summary
Attributes inherited from AbstractProvider
Instance Method Summary collapse
-
#initialize ⇒ WorldCatProvider
constructor
A new instance of WorldCatProvider.
- #search(criterion, type) ⇒ Object
- #url(book) ⇒ Object
Methods included from Logging
Methods inherited from WebsiteBasedProvider
Methods inherited from AbstractProvider
#<=>, #abstract?, abstract?, #action_name, #enabled, #reinitialize, #remove, #toggle_enabled, #transport, unabstract, #variable_name
Constructor Details
#initialize ⇒ WorldCatProvider
Returns a new instance of WorldCatProvider.
30 31 32 33 |
# File 'lib/alexandria/book_providers/worldcat.rb', line 30 def initialize super("WorldCat", "WorldCat") prefs.read end |
Instance Method Details
#search(criterion, type) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/alexandria/book_providers/worldcat.rb', line 35 def search(criterion, type) req = create_search_uri(type, criterion) html_data = transport.get_response(URI.parse(req)) if type == SEARCH_BY_ISBN parse_result_data(html_data.body, criterion) else results = parse_search_result_data(html_data.body) raise NoResultsError if results.empty? results.map { |result| get_book_from_search_result(result) } end end |
#url(book) ⇒ Object
49 50 51 |
# File 'lib/alexandria/book_providers/worldcat.rb', line 49 def url(book) create_search_uri(SEARCH_BY_ISBN, book.isbn) end |