Module: BookWorm::Searchable
- Included in:
- BookWorm
- Defined in:
- lib/book_worm/searchable.rb
Overview
Searchable
A module that implements the basic finder methods for accessing the ISBNdb API
Constant Summary collapse
- INDICES =
Searchable indices
These indices represent the BookWorm supported searching methods
[:isbn, :title, :combined, :full]
Instance Method Summary collapse
-
#find(*args) ⇒ Object
Given a valid index and a value, this method returns the first match found after querying ISBNdb.
-
#find_all(*args) ⇒ Object
Given a valid index and a value, this method returns the all matches found after querying ISBNdb.
Instance Method Details
#find(*args) ⇒ Object
Given a valid index and a value, this method returns the first match found after querying ISBNdb. The default index, :isbn, will be used in the event that you only supply one argument
Example Usage
Query ISBNdb with an isbn-10
BookWorm.find(:isbn, "1234567890")
BookWorm.find("1234567890")
Query ISBNdb with an isbn-13
BookWorm.find(:isbn, "1234567890123")
BookWorm.find("1234567890123")
Query ISBNdb with a title
BookWorm.find(:title, "Programming Ruby")
Query ISBNdb with a combined index. Search index that combines titles, authors, and publisher name.
BookWorm.find(:combined, "Programming Ruby")
Query ISBNdb with a full index. A full index includes titles, authors, publisher name, summary, notes, awards information, etc – practically every bit of textual information ISBNdb.com has about books.
BookWorm.find(:full, "Programming Ruby")
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/book_worm/searchable.rb', line 73 def find(*args) if args.size == 1 index = :isbn value = args[0] else index = INDICES.include?(args[0]) ? args[0] : :isbn value = args[1] end normalize(query_isbndb(index, value))[0] end |
#find_all(*args) ⇒ Object
Given a valid index and a value, this method returns the all matches found after querying ISBNdb. The default index, :full, will be used in the event that you only supply one argument
Example Usage
Query ISBNdb with an isbn-10
BookWorm.find_all(:isbn, "1234567890")
Query ISBNdb with an isbn-13
BookWorm.find_all(:isbn, "1234567890123")
Query ISBNdb with a title
BookWorm.find_all(:title, "Programming Ruby")
Query ISBNdb with a combined index. Search index that combines titles, authors, and publisher name.
BookWorm.find_all(:combined, "Programming Ruby")
Query ISBNdb with a full index. A full index includes titles, authors, publisher name, summary, notes, awards information, etc – practically every bit of textual information ISBNdb.com has about books.
BookWorm.find_all(:full, "Programming Ruby")
BookWorm.find("Programming Ruby")
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/book_worm/searchable.rb', line 109 def find_all(*args) if args.size == 1 index = :full value = args[0] else index = INDICES.include?(args[0]) ? args[0] : :full value = args[1] end normalize(query_isbndb(index, value)) end |