book_worm 0.0.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,28 +1,28 @@
1
- PATH
2
- remote: .
3
- specs:
4
- book_worm (0.0.3)
5
- httparty
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- crack (0.1.8)
11
- diff-lcs (1.1.2)
12
- httparty (0.6.1)
13
- crack (= 0.1.8)
14
- rspec (2.0.0.beta.20)
15
- rspec-core (= 2.0.0.beta.20)
16
- rspec-expectations (= 2.0.0.beta.20)
17
- rspec-mocks (= 2.0.0.beta.20)
18
- rspec-core (2.0.0.beta.20)
19
- rspec-expectations (2.0.0.beta.20)
20
- diff-lcs (>= 1.1.2)
21
- rspec-mocks (2.0.0.beta.20)
22
-
23
- PLATFORMS
24
- ruby
25
-
26
- DEPENDENCIES
27
- book_worm!
28
- rspec
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ book_worm (0.1.5)
5
+ httparty
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ crack (0.1.8)
11
+ diff-lcs (1.1.2)
12
+ httparty (0.6.1)
13
+ crack (= 0.1.8)
14
+ rspec (2.0.0.beta.20)
15
+ rspec-core (= 2.0.0.beta.20)
16
+ rspec-expectations (= 2.0.0.beta.20)
17
+ rspec-mocks (= 2.0.0.beta.20)
18
+ rspec-core (2.0.0.beta.20)
19
+ rspec-expectations (2.0.0.beta.20)
20
+ diff-lcs (>= 1.1.2)
21
+ rspec-mocks (2.0.0.beta.20)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ book_worm!
28
+ rspec
@@ -1,21 +1,21 @@
1
- module BookWorm
2
-
3
- # == Book
4
- #
5
- # Book is used to store the xml data that is returned from ISBNDB
6
- class Book
7
- attr_accessor :publisher, :authors, :isbn,
8
- :isbn13, :title, :long_title,
9
- :book_id
10
-
11
- def initialize(book_data)
12
- self.long_title = book_data["TitleLong"]
13
- self.publisher = book_data["PublisherText"]
14
- self.authors = book_data["AuthorsText"]
15
- self.isbn = book_data["isbn"]
16
- self.isbn13 = book_data["isbn13"]
17
- self.title = book_data["Title"]
18
- self.book_id = book_data["book_id"]
19
- end
20
- end
21
- end
1
+ module BookWorm
2
+
3
+ # == Book
4
+ #
5
+ # Book is used to store the xml data that is returned from ISBNDB
6
+ class Book
7
+ attr_accessor :publisher, :authors, :isbn,
8
+ :isbn13, :title, :long_title,
9
+ :book_id
10
+
11
+ def initialize(book_data)
12
+ self.long_title = book_data["TitleLong"]
13
+ self.publisher = book_data["PublisherText"]
14
+ self.authors = book_data["AuthorsText"].chop.chop
15
+ self.isbn = book_data["isbn"]
16
+ self.isbn13 = book_data["isbn13"]
17
+ self.title = book_data["Title"]
18
+ self.book_id = book_data["book_id"]
19
+ end
20
+ end
21
+ end
@@ -1,145 +1,145 @@
1
- module BookWorm
2
- require 'book_worm/book'
3
- require 'httparty'
4
-
5
- include HTTParty
6
- format :xml
7
- base_uri 'http://isbndb.com'
8
-
9
- # == Searchable
10
- #
11
- # A module that implements the basic finder methods for accessing the ISBNdb API
12
- #
13
- module Searchable
14
-
15
- # == Searchable indices
16
- #
17
- # These indices represent the BookWorm supported searching methods
18
- #
19
- INDICES = [:isbn, :title, :combined, :full]
20
-
21
- # Define convenience methods for #find and #find_all.
22
- #
23
- # == Example Usage
24
- #
25
- # BookWorm.find_by_isbn("1234567890")
26
- # BookWorm.find_by_title("Programming Ruby")
27
- # BookWorm.find_by_combined_index("Programming Ruby")
28
- # BookWorm.find_by_full_index("Programming Ruby")
29
- #
30
- # BookWorm.find_all_by_isbn("1234567890")
31
- # BookWorm.find_all_by_title("Programming Ruby")
32
- # BookWorm.find_all_by_combined_index("Programming Ruby")
33
- # BookWorm.find_all_by_full_index("Programming Ruby")
34
- #
35
- INDICES.each do |index|
36
- index_name = (index.to_s =~ /full|combined/ ? "#{index}_index" : index)
37
-
38
- define_method "find_by_#{index_name}" do |arg|
39
- find(index, arg)
40
- end
41
-
42
- define_method "find_all_by_#{index_name}" do |arg|
43
- find_all(index, arg)
44
- end
45
- end
46
-
47
- # Given a valid index and a value, this method returns the first match found
48
- # after querying ISBNdb. The default index, :isbn, will be used
49
- # in the event that you only supply one argument
50
- #
51
- # == Example Usage
52
- #
53
- # Query ISBNdb with an isbn-10
54
- # BookWorm.find(:isbn, "1234567890")
55
- # BookWorm.find("1234567890")
56
- #
57
- # Query ISBNdb with an isbn-13
58
- # BookWorm.find(:isbn, "1234567890123")
59
- # BookWorm.find("1234567890123")
60
- #
61
- # Query ISBNdb with a title
62
- # BookWorm.find(:title, "Programming Ruby")
63
- #
64
- # Query ISBNdb with a combined index. Search index that combines titles, authors, and
65
- # publisher name.
66
- # BookWorm.find(:combined, "Programming Ruby")
67
- #
68
- # Query ISBNdb with a full index. A full index includes titles, authors, publisher
69
- # name, summary, notes, awards information, etc -- practically every bit of textual
70
- # information ISBNdb.com has about books.
71
- # BookWorm.find(:full, "Programming Ruby")
72
- #
73
- def find(*args)
74
- if args.size == 1
75
- index = :isbn
76
- value = args[0]
77
- else
78
- index = INDICES.include?(args[0]) ? args[0] : :isbn
79
- value = args[1]
80
- end
81
- normalize(query_isbndb(index, value))[0]
82
- end
83
-
84
- # Given a valid index and a value, this method returns the all matches found
85
- # after querying ISBNdb. The default index, :full, will be used
86
- # in the event that you only supply one argument
87
- #
88
- # == Example Usage
89
- #
90
- # Query ISBNdb with an isbn-10
91
- # BookWorm.find_all(:isbn, "1234567890")
92
- #
93
- # Query ISBNdb with an isbn-13
94
- # BookWorm.find_all(:isbn, "1234567890123")
95
- #
96
- # Query ISBNdb with a title
97
- # BookWorm.find_all(:title, "Programming Ruby")
98
- #
99
- # Query ISBNdb with a combined index. Search index that combines titles, authors, and
100
- # publisher name.
101
- # BookWorm.find_all(:combined, "Programming Ruby")
102
- #
103
- # Query ISBNdb with a full index. A full index includes titles, authors, publisher
104
- # name, summary, notes, awards information, etc -- practically every bit of textual
105
- # information ISBNdb.com has about books.
106
- # BookWorm.find_all(:full, "Programming Ruby")
107
- # BookWorm.find("Programming Ruby")
108
- #
109
- def find_all(*args)
110
- if args.size == 1
111
- index = :full
112
- value = args[0]
113
- else
114
- index = INDICES.include?(args[0]) ? args[0] : :full
115
- value = args[1]
116
- end
117
- normalize(query_isbndb(index, value))
118
- end
119
-
120
- private
121
-
122
- # :nodoc:
123
- def query_base
124
- "/api/books.xml"
125
- end
126
-
127
- # :nodoc:
128
- def query_isbndb(index, value)
129
- get(query_base, :query => { :index1 => index,
130
- :value1 => value,
131
- :access_key => Configuration.config[:api_key], })
132
- end
133
-
134
- # :nodoc:
135
- def normalize(results)
136
- begin
137
- [results['ISBNdb']['BookList']['BookData']].flatten.collect do |book|
138
- Book.new(book)
139
- end
140
- rescue
141
- []
142
- end
143
- end
144
- end
145
- end
1
+ module BookWorm
2
+ require 'book_worm/book'
3
+ require 'httparty'
4
+
5
+ include HTTParty
6
+ format :xml
7
+ base_uri 'http://isbndb.com'
8
+
9
+ # == Searchable
10
+ #
11
+ # A module that implements the basic finder methods for accessing the ISBNdb API
12
+ #
13
+ module Searchable
14
+
15
+ # == Searchable indices
16
+ #
17
+ # These indices represent the BookWorm supported searching methods
18
+ #
19
+ INDICES = [:isbn, :title, :combined, :full]
20
+
21
+ # Define convenience methods for #find and #find_all.
22
+ #
23
+ # == Example Usage
24
+ #
25
+ # BookWorm.find_by_isbn("1234567890")
26
+ # BookWorm.find_by_title("Programming Ruby")
27
+ # BookWorm.find_by_combined_index("Programming Ruby")
28
+ # BookWorm.find_by_full_index("Programming Ruby")
29
+ #
30
+ # BookWorm.find_all_by_isbn("1234567890")
31
+ # BookWorm.find_all_by_title("Programming Ruby")
32
+ # BookWorm.find_all_by_combined_index("Programming Ruby")
33
+ # BookWorm.find_all_by_full_index("Programming Ruby")
34
+ #
35
+ INDICES.each do |index|
36
+ index_name = (index.to_s =~ /full|combined/ ? "#{index}_index" : index)
37
+
38
+ define_method "find_by_#{index_name}" do |arg|
39
+ find(index, arg)
40
+ end
41
+
42
+ define_method "find_all_by_#{index_name}" do |arg|
43
+ find_all(index, arg)
44
+ end
45
+ end
46
+
47
+ # Given a valid index and a value, this method returns the first match found
48
+ # after querying ISBNdb. The default index, :isbn, will be used
49
+ # in the event that you only supply one argument
50
+ #
51
+ # == Example Usage
52
+ #
53
+ # Query ISBNdb with an isbn-10
54
+ # BookWorm.find(:isbn, "1234567890")
55
+ # BookWorm.find("1234567890")
56
+ #
57
+ # Query ISBNdb with an isbn-13
58
+ # BookWorm.find(:isbn, "1234567890123")
59
+ # BookWorm.find("1234567890123")
60
+ #
61
+ # Query ISBNdb with a title
62
+ # BookWorm.find(:title, "Programming Ruby")
63
+ #
64
+ # Query ISBNdb with a combined index. Search index that combines titles, authors, and
65
+ # publisher name.
66
+ # BookWorm.find(:combined, "Programming Ruby")
67
+ #
68
+ # Query ISBNdb with a full index. A full index includes titles, authors, publisher
69
+ # name, summary, notes, awards information, etc -- practically every bit of textual
70
+ # information ISBNdb.com has about books.
71
+ # BookWorm.find(:full, "Programming Ruby")
72
+ #
73
+ def find(*args)
74
+ if args.size == 1
75
+ index = :isbn
76
+ value = args[0]
77
+ else
78
+ index = INDICES.include?(args[0]) ? args[0] : :isbn
79
+ value = args[1]
80
+ end
81
+ normalize(query_isbndb(index, value))[0]
82
+ end
83
+
84
+ # Given a valid index and a value, this method returns the all matches found
85
+ # after querying ISBNdb. The default index, :full, will be used
86
+ # in the event that you only supply one argument
87
+ #
88
+ # == Example Usage
89
+ #
90
+ # Query ISBNdb with an isbn-10
91
+ # BookWorm.find_all(:isbn, "1234567890")
92
+ #
93
+ # Query ISBNdb with an isbn-13
94
+ # BookWorm.find_all(:isbn, "1234567890123")
95
+ #
96
+ # Query ISBNdb with a title
97
+ # BookWorm.find_all(:title, "Programming Ruby")
98
+ #
99
+ # Query ISBNdb with a combined index. Search index that combines titles, authors, and
100
+ # publisher name.
101
+ # BookWorm.find_all(:combined, "Programming Ruby")
102
+ #
103
+ # Query ISBNdb with a full index. A full index includes titles, authors, publisher
104
+ # name, summary, notes, awards information, etc -- practically every bit of textual
105
+ # information ISBNdb.com has about books.
106
+ # BookWorm.find_all(:full, "Programming Ruby")
107
+ # BookWorm.find("Programming Ruby")
108
+ #
109
+ def find_all(*args)
110
+ if args.size == 1
111
+ index = :full
112
+ value = args[0]
113
+ else
114
+ index = INDICES.include?(args[0]) ? args[0] : :full
115
+ value = args[1]
116
+ end
117
+ normalize(query_isbndb(index, value))
118
+ end
119
+
120
+ private
121
+
122
+ # :nodoc:
123
+ def query_base
124
+ "/api/books.xml"
125
+ end
126
+
127
+ # :nodoc:
128
+ def query_isbndb(index, value)
129
+ get(query_base, :query => { :index1 => index,
130
+ :value1 => value,
131
+ :access_key => Configuration.config[:api_key], })
132
+ end
133
+
134
+ # :nodoc:
135
+ def normalize(results)
136
+ begin
137
+ [results['ISBNdb']['BookList']['BookData']].flatten.collect do |book|
138
+ Book.new(book)
139
+ end
140
+ rescue
141
+ []
142
+ end
143
+ end
144
+ end
145
+ end
@@ -1,3 +1,3 @@
1
1
  module BookWorm
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/spec/book_spec.rb CHANGED
@@ -1,229 +1,229 @@
1
- require 'spec_helper'
2
- require 'book_worm'
3
-
4
- describe BookWorm do
5
- describe '#find' do
6
- context 'when a search results in no matches' do
7
- it 'returns nil' do
8
- BookWorm.find(:isbn, 'Jiveturkey').should be_nil
9
- end
10
- end
11
-
12
- context 'when finding without a specified index' do
13
- it 'defaults to an isbn index' do
14
- BookWorm.find('1934356085').isbn.should == '1934356085'
15
- end
16
- end
17
-
18
- context 'when finding with a non-supported index' do
19
- it 'defaults to an isbn index' do
20
- BookWorm.should_receive(:query_isbndb).with(:isbn, '1934356085')
21
- BookWorm.find(:jiveturkey, '1934356085')
22
- end
23
- end
24
-
25
- before :each do
26
- @book_data = { :isbn => "1934356085",
27
- :isbn13 => "9781934356081",
28
- :book_id => "programming_ruby_1_9",
29
- :publisher => "Pragmatic Bookshelf",
30
- :title => 'Programming Ruby 1.9',
31
- :long_title => "Programming Ruby 1.9: The Pragmatic Programmers' Guide",
32
- :authors => "Dave Thomas, Chad Fowler, Andy Hunt, " }
33
- end
34
-
35
- context 'when querying for a book by isbn' do
36
- it 'indexes by isbn.' do
37
- result = BookWorm.find(:isbn, @book_data[:isbn])
38
- @book_data.each do |key,val|
39
- result.send(key).should == val
40
- end
41
- end
42
-
43
- it 'indexes by isbn13.' do
44
- result = BookWorm.find(:isbn, @book_data[:isbn13])
45
- @book_data.each do |key,val|
46
- result.send(key).should == val
47
- end
48
- end
49
-
50
- context 'when using #find_book hepers' do
51
- it 'indexes by isbn more easily.' do
52
- result = BookWorm.find_by_isbn(@book_data[:isbn])
53
- @book_data.each do |key,val|
54
- result.send(key).should == val
55
- end
56
- end
57
-
58
- it 'indexes by isbn13 more conveniently.' do
59
- result = BookWorm.find_by_isbn(@book_data[:isbn13])
60
- @book_data.each do |key,val|
61
- result.send(key).should == val
62
- end
63
- end
64
- end
65
-
66
- context 'when querying for a book by title' do
67
- it 'indexes books by title' do
68
- result = BookWorm.find(:title, @book_data[:title])
69
- @book_data.each do |key,val|
70
- result.send(key).should == val
71
- end
72
- end
73
-
74
- context 'when using #find_book helpers' do
75
- it 'indexes by title more conveniently.' do
76
- result = BookWorm.find_by_title(@book_data[:title])
77
- @book_data.each do |key,val|
78
- result.send(key).should == val
79
- end
80
- end
81
- end
82
- end
83
-
84
- context 'when querying for a book by combined index' do
85
- before :each do
86
- @combined_index = "#{@book_data[:title]} #{@book_data[:publisher]} #{@book_data[:authors]}"
87
- end
88
-
89
- it 'indexes using several combined fields' do
90
- @combined_index = "#{@book_data[:title]} #{@book_data[:publisher]} #{@book_data[:authors]}"
91
- result = BookWorm.find(:combined, @combined_index)
92
- @book_data.each do |key,val|
93
- result.send(key).should == val
94
- end
95
- end
96
-
97
- context 'when querying for a book by combined index' do
98
- it 'uses combined index more conveniently.' do
99
- result = BookWorm.find_by_combined_index(@combined_index)
100
- @book_data.each do |key,val|
101
- result.send(key).should == val
102
- end
103
- end
104
- end
105
- end
106
-
107
- context 'when querying for a book by full index' do
108
- before :each do
109
- @summary = "making Ruby a favorite tool of intelligent, forward-thinking programmers"
110
- end
111
-
112
- it 'indexes using several full fields' do
113
- result = BookWorm.find(:full, @summary)
114
- @book_data.each do |key,val|
115
- result.send(key).should == val
116
- end
117
- end
118
-
119
- context 'when querying for a book by full index' do
120
- it 'uses full index more conveniently.' do
121
- result = BookWorm.find_by_full_index(@summary)
122
- @book_data.each do |key,val|
123
- result.send(key).should == val
124
- end
125
- end
126
- end
127
- end
128
- end
129
- end # end find
130
-
131
- describe '#find_all' do
132
- context 'when querying for a collection of books' do
133
- it 'returns an empty array when no results are found' do
134
- BookWorm.find_all(:isbn, 'Jiveturkey').should be_empty
135
- end
136
- end
137
-
138
- context 'when finding without a specified index' do
139
- it 'defaults to full index' do
140
- BookWorm.should_receive(:query_isbndb).with(:full, "foobarbaz")
141
- BookWorm.find_all('foobarbaz')
142
- end
143
- end
144
-
145
- context 'when finding with a non-supported index' do
146
- it 'defaults to a full index' do
147
- BookWorm.should_receive(:query_isbndb).with(:full, '1934356085')
148
- BookWorm.find_all(:jiveturkey, '1934356085')
149
- end
150
- end
151
-
152
- context 'when querying for a collection of books by isbn' do
153
- it 'indexes by isbn' do
154
- BookWorm.find_all(:isbn, '1934356085').each do |book|
155
- book.isbn.should == '1934356085'
156
- end
157
- end
158
-
159
- it 'indexes by isbn13' do
160
- BookWorm.find_all(:isbn, '9781934356081').each do |book|
161
- book.isbn13.should == '9781934356081'
162
- end
163
- end
164
-
165
- context 'when using #find_all convenience helpers' do
166
- it 'conveniently indexes by isbn' do
167
- BookWorm.find_all_by_isbn('1934356085').each do |book|
168
- book.isbn.should == '1934356085'
169
- end
170
- end
171
-
172
- it 'conveniently indexes by isbn13' do
173
- BookWorm.find_all_by_isbn('9781934356081').each do |book|
174
- book.isbn13.should == '9781934356081'
175
- end
176
- end
177
- end
178
- end
179
-
180
- context 'when querying for a collection of books by title' do
181
- it 'has results that contain the title argument' do
182
- BookWorm.find_all(:title, 'Ruby Rails').each do |book|
183
- book.title.should =~ /ruby|rails/i
184
- end
185
- end
186
-
187
- context 'when using #find_books helpers' do
188
- it 'has results that contain the title argument' do
189
- BookWorm.find_all_by_title('Ruby Rails').each do |book|
190
- book.title.should =~ /ruby|rails/i
191
- end
192
- end
193
- end
194
- end
195
-
196
- context 'when querying for a collection of books by a combined index' do
197
- it 'has results that contain the arguments' do
198
- BookWorm.find_all(:combined, 'Ruby Rails').each do |book|
199
- book.title.should =~ /ruby|rails/i
200
- end
201
- end
202
-
203
- context 'when using #find_books helpers' do
204
- it 'has results that contain the arguments' do
205
- BookWorm.find_all_by_combined_index('Ruby Hansson Pragmatic Rails').each do |book|
206
- title = book.title =~ /ruby|rails/i
207
- author = book.authors =~ /hansson/i
208
- publisher = book.publisher =~ /pragmatic/i
209
- (title || author || publisher).should be_true
210
- end
211
- end
212
- end
213
- end
214
-
215
- context 'when querying for a collection of books by a full index' do
216
- it 'has results that match the full index' do
217
- books = BookWorm.find_all(:full, 'Ruby Rails Pragmatic Programming')
218
- books.collect{ |book| book.title }.join('_').should =~ /ruby|rails/i
219
- end
220
-
221
- context 'when using #find_books helpers' do
222
- it 'has results that contain the arguments for full index search' do
223
- books = BookWorm.find_all_by_full_index('Ruby Rails Pragmatic Programming')
224
- books.collect{ |book| book.title }.join('_').should =~ /ruby|rails/i
225
- end
226
- end
227
- end
228
- end #end find_all
229
- end
1
+ require 'spec_helper'
2
+ require 'book_worm'
3
+
4
+ describe BookWorm do
5
+ describe '#find' do
6
+ context 'when a search results in no matches' do
7
+ it 'returns nil' do
8
+ BookWorm.find(:isbn, 'Jiveturkey').should be_nil
9
+ end
10
+ end
11
+
12
+ context 'when finding without a specified index' do
13
+ it 'defaults to an isbn index' do
14
+ BookWorm.find('1934356085').isbn.should == '1934356085'
15
+ end
16
+ end
17
+
18
+ context 'when finding with a non-supported index' do
19
+ it 'defaults to an isbn index' do
20
+ BookWorm.should_receive(:query_isbndb).with(:isbn, '1934356085')
21
+ BookWorm.find(:jiveturkey, '1934356085')
22
+ end
23
+ end
24
+
25
+ before :each do
26
+ @book_data = { :isbn => "1934356085",
27
+ :isbn13 => "9781934356081",
28
+ :book_id => "programming_ruby_1_9",
29
+ :publisher => "Pragmatic Bookshelf",
30
+ :title => 'Programming Ruby 1.9',
31
+ :long_title => "Programming Ruby 1.9: The Pragmatic Programmers' Guide",
32
+ :authors => "Dave Thomas, Chad Fowler, Andy Hunt" }
33
+ end
34
+
35
+ context 'when querying for a book by isbn' do
36
+ it 'indexes by isbn.' do
37
+ result = BookWorm.find(:isbn, @book_data[:isbn])
38
+ @book_data.each do |key,val|
39
+ result.send(key).should == val
40
+ end
41
+ end
42
+
43
+ it 'indexes by isbn13.' do
44
+ result = BookWorm.find(:isbn, @book_data[:isbn13])
45
+ @book_data.each do |key,val|
46
+ result.send(key).should == val
47
+ end
48
+ end
49
+
50
+ context 'when using #find_book hepers' do
51
+ it 'indexes by isbn more easily.' do
52
+ result = BookWorm.find_by_isbn(@book_data[:isbn])
53
+ @book_data.each do |key,val|
54
+ result.send(key).should == val
55
+ end
56
+ end
57
+
58
+ it 'indexes by isbn13 more conveniently.' do
59
+ result = BookWorm.find_by_isbn(@book_data[:isbn13])
60
+ @book_data.each do |key,val|
61
+ result.send(key).should == val
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'when querying for a book by title' do
67
+ it 'indexes books by title' do
68
+ result = BookWorm.find(:title, @book_data[:title])
69
+ @book_data.each do |key,val|
70
+ result.send(key).should == val
71
+ end
72
+ end
73
+
74
+ context 'when using #find_book helpers' do
75
+ it 'indexes by title more conveniently.' do
76
+ result = BookWorm.find_by_title(@book_data[:title])
77
+ @book_data.each do |key,val|
78
+ result.send(key).should == val
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ context 'when querying for a book by combined index' do
85
+ before :each do
86
+ @combined_index = "#{@book_data[:title]} #{@book_data[:publisher]} #{@book_data[:authors]}"
87
+ end
88
+
89
+ it 'indexes using several combined fields' do
90
+ @combined_index = "#{@book_data[:title]} #{@book_data[:publisher]} #{@book_data[:authors]}"
91
+ result = BookWorm.find(:combined, @combined_index)
92
+ @book_data.each do |key,val|
93
+ result.send(key).should == val
94
+ end
95
+ end
96
+
97
+ context 'when querying for a book by combined index' do
98
+ it 'uses combined index more conveniently.' do
99
+ result = BookWorm.find_by_combined_index(@combined_index)
100
+ @book_data.each do |key,val|
101
+ result.send(key).should == val
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ context 'when querying for a book by full index' do
108
+ before :each do
109
+ @summary = "making Ruby a favorite tool of intelligent, forward-thinking programmers"
110
+ end
111
+
112
+ it 'indexes using several full fields' do
113
+ result = BookWorm.find(:full, @summary)
114
+ @book_data.each do |key,val|
115
+ result.send(key).should == val
116
+ end
117
+ end
118
+
119
+ context 'when querying for a book by full index' do
120
+ it 'uses full index more conveniently.' do
121
+ result = BookWorm.find_by_full_index(@summary)
122
+ @book_data.each do |key,val|
123
+ result.send(key).should == val
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end # end find
130
+
131
+ describe '#find_all' do
132
+ context 'when querying for a collection of books' do
133
+ it 'returns an empty array when no results are found' do
134
+ BookWorm.find_all(:isbn, 'Jiveturkey').should be_empty
135
+ end
136
+ end
137
+
138
+ context 'when finding without a specified index' do
139
+ it 'defaults to full index' do
140
+ BookWorm.should_receive(:query_isbndb).with(:full, "foobarbaz")
141
+ BookWorm.find_all('foobarbaz')
142
+ end
143
+ end
144
+
145
+ context 'when finding with a non-supported index' do
146
+ it 'defaults to a full index' do
147
+ BookWorm.should_receive(:query_isbndb).with(:full, '1934356085')
148
+ BookWorm.find_all(:jiveturkey, '1934356085')
149
+ end
150
+ end
151
+
152
+ context 'when querying for a collection of books by isbn' do
153
+ it 'indexes by isbn' do
154
+ BookWorm.find_all(:isbn, '1934356085').each do |book|
155
+ book.isbn.should == '1934356085'
156
+ end
157
+ end
158
+
159
+ it 'indexes by isbn13' do
160
+ BookWorm.find_all(:isbn, '9781934356081').each do |book|
161
+ book.isbn13.should == '9781934356081'
162
+ end
163
+ end
164
+
165
+ context 'when using #find_all convenience helpers' do
166
+ it 'conveniently indexes by isbn' do
167
+ BookWorm.find_all_by_isbn('1934356085').each do |book|
168
+ book.isbn.should == '1934356085'
169
+ end
170
+ end
171
+
172
+ it 'conveniently indexes by isbn13' do
173
+ BookWorm.find_all_by_isbn('9781934356081').each do |book|
174
+ book.isbn13.should == '9781934356081'
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ context 'when querying for a collection of books by title' do
181
+ it 'has results that contain the title argument' do
182
+ BookWorm.find_all(:title, 'Ruby Rails').each do |book|
183
+ book.title.should =~ /ruby|rails/i
184
+ end
185
+ end
186
+
187
+ context 'when using #find_books helpers' do
188
+ it 'has results that contain the title argument' do
189
+ BookWorm.find_all_by_title('Ruby Rails').each do |book|
190
+ book.title.should =~ /ruby|rails/i
191
+ end
192
+ end
193
+ end
194
+ end
195
+
196
+ context 'when querying for a collection of books by a combined index' do
197
+ it 'has results that contain the arguments' do
198
+ BookWorm.find_all(:combined, 'Ruby Rails').each do |book|
199
+ book.title.should =~ /ruby|rails/i
200
+ end
201
+ end
202
+
203
+ context 'when using #find_books helpers' do
204
+ it 'has results that contain the arguments' do
205
+ BookWorm.find_all_by_combined_index('Ruby Hansson Pragmatic Rails').each do |book|
206
+ title = book.title =~ /ruby|rails/i
207
+ author = book.authors =~ /hansson/i
208
+ publisher = book.publisher =~ /pragmatic/i
209
+ (title || author || publisher).should be_true
210
+ end
211
+ end
212
+ end
213
+ end
214
+
215
+ context 'when querying for a collection of books by a full index' do
216
+ it 'has results that match the full index' do
217
+ books = BookWorm.find_all(:full, 'Ruby Rails Pragmatic Programming')
218
+ books.collect{ |book| book.title }.join('_').should =~ /ruby|rails/i
219
+ end
220
+
221
+ context 'when using #find_books helpers' do
222
+ it 'has results that contain the arguments for full index search' do
223
+ books = BookWorm.find_all_by_full_index('Ruby Rails Pragmatic Programming')
224
+ books.collect{ |book| book.title }.join('_').should =~ /ruby|rails/i
225
+ end
226
+ end
227
+ end
228
+ end #end find_all
229
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'rspec'
2
- require 'book_worm'
3
-
4
- BookWorm::Configuration.configure do |c|
5
- c[:api_key] = "Your API key"
6
- end
7
-
1
+ require 'rspec'
2
+ require 'book_worm'
3
+
4
+ BookWorm::Configuration.configure do |c|
5
+ c[:api_key] = "Your API key"
6
+ end
7
+
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: book_worm
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 4
9
- version: 0.0.4
4
+ prerelease:
5
+ version: 0.1.5
10
6
  platform: ruby
11
7
  authors:
12
8
  - Tony Schneider
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-02-14 00:00:00 -05:00
13
+ date: 2011-03-08 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,8 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
24
  version: "0"
31
25
  type: :runtime
32
26
  version_requirements: *id001
@@ -38,8 +32,6 @@ dependencies:
38
32
  requirements:
39
33
  - - ">="
40
34
  - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
35
  version: "0"
44
36
  type: :development
45
37
  version_requirements: *id002
@@ -82,21 +74,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
74
  requirements:
83
75
  - - ">="
84
76
  - !ruby/object:Gem::Version
85
- segments:
86
- - 0
87
77
  version: "0"
88
78
  required_rubygems_version: !ruby/object:Gem::Requirement
89
79
  none: false
90
80
  requirements:
91
81
  - - ">="
92
82
  - !ruby/object:Gem::Version
93
- segments:
94
- - 0
95
83
  version: "0"
96
84
  requirements: []
97
85
 
98
86
  rubyforge_project: book_worm
99
- rubygems_version: 1.3.7
87
+ rubygems_version: 1.5.2
100
88
  signing_key:
101
89
  specification_version: 3
102
90
  summary: A simple gem for interacting with ISBNDB.com