Class: QuickSearch::OpenLibrarySearcher
- Inherits:
-
Searcher
- Object
- Searcher
- QuickSearch::OpenLibrarySearcher
- Defined in:
- app/searchers/quick_search/open_library_searcher.rb
Instance Method Summary collapse
- #author(value) ⇒ Object
- #base_url ⇒ Object
- #build_link(value) ⇒ Object
- #cover_image(value) ⇒ Object
- #loaded_link ⇒ Object
- #parameters ⇒ Object
- #results ⇒ Object
- #search ⇒ Object
- #title(value) ⇒ Object
- #total ⇒ Object
Instance Method Details
#author(value) ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 46 def (value) if value.has_key?('author_name') value['author_name'].join(', ') else "" end end |
#base_url ⇒ Object
32 33 34 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 32 def base_url "http://openlibrary.org/search.json" end |
#build_link(value) ⇒ Object
58 59 60 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 58 def build_link(value) "http://www.openlibrary.org" + value['key'] end |
#cover_image(value) ⇒ Object
70 71 72 73 74 75 76 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 70 def cover_image(value) if value.has_key?('cover_i') "https://covers.openlibrary.org/w/id/" + value['cover_i'].to_s + "-M.jpg" else "" end end |
#loaded_link ⇒ Object
54 55 56 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 54 def loaded_link "http://www.openlibrary.org/search?q=" + http_request_queries['uri_escaped'] end |
#parameters ⇒ Object
36 37 38 39 40 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 36 def parameters { 'q' => http_request_queries['not_escaped'], } end |
#results ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 9 def results if results_list results_list else @results_list = [] @response['docs'].first(@per_page).each do |value| result = OpenStruct.new result.title = title(value) result.link = build_link(value) result. = (value) result.date = value['first_publish_year'] result.fulltext = value['has_fulltext'] result.thumbnail = cover_image(value) @results_list << result end @results_list end end |
#search ⇒ Object
4 5 6 7 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 4 def search resp = @http.get(base_url, parameters) @response = JSON.parse(resp.body) end |
#title(value) ⇒ Object
62 63 64 65 66 67 68 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 62 def title(value) if value.has_key?('subtitle') value['title'] + ': ' + value['subtitle'] else value['title'] end end |
#total ⇒ Object
42 43 44 |
# File 'app/searchers/quick_search/open_library_searcher.rb', line 42 def total @response['numFound'] end |