book_worm 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/book_worm/book.rb +19 -8
- data/lib/book_worm/searchable.rb +1 -0
- data/lib/book_worm/version.rb +1 -1
- data/spec/book_spec.rb +17 -0
- data/spec/spec_helper.rb +7 -7
- metadata +2 -2
data/lib/book_worm/book.rb
CHANGED
|
@@ -6,16 +6,27 @@ module BookWorm
|
|
|
6
6
|
class Book
|
|
7
7
|
attr_accessor :publisher, :authors, :isbn,
|
|
8
8
|
:isbn13, :title, :long_title,
|
|
9
|
-
:book_id
|
|
9
|
+
:book_id, :average_price
|
|
10
10
|
|
|
11
11
|
def initialize(book_data)
|
|
12
|
-
self.long_title
|
|
13
|
-
self.publisher
|
|
14
|
-
self.authors
|
|
15
|
-
self.isbn
|
|
16
|
-
self.isbn13
|
|
17
|
-
self.title
|
|
18
|
-
self.book_id
|
|
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
|
+
self.average_price = average_price_listed(book_data["Prices"]['Price'])
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def average_price_listed(listings)
|
|
25
|
+
sum = 0
|
|
26
|
+
listings.each do |listing|
|
|
27
|
+
sum += listing["price"].to_f
|
|
28
|
+
end
|
|
29
|
+
(sum / listings.size).round(2)
|
|
19
30
|
end
|
|
20
31
|
end
|
|
21
32
|
end
|
data/lib/book_worm/searchable.rb
CHANGED
data/lib/book_worm/version.rb
CHANGED
data/spec/book_spec.rb
CHANGED
|
@@ -226,4 +226,21 @@ describe BookWorm do
|
|
|
226
226
|
end
|
|
227
227
|
end
|
|
228
228
|
end #end find_all
|
|
229
|
+
|
|
230
|
+
context 'by default include current average price of found books' do
|
|
231
|
+
context 'when using a find method' do
|
|
232
|
+
it 'includes prices' do
|
|
233
|
+
book = BookWorm.find(:isbn, '9781934356050')
|
|
234
|
+
book.average_price.to_s.should =~ /\d+\.\d{2}/
|
|
235
|
+
end
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
context 'when using a find_all method' do
|
|
239
|
+
it 'includes prices' do
|
|
240
|
+
BookWorm.find_all(:combined, 'Ruby Rails').each do |book|
|
|
241
|
+
book.average_price.to_s.should =~ /\d+\.\d{2}/
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
end
|
|
229
246
|
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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: book_worm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.1.
|
|
5
|
+
version: 0.1.6
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Tony Schneider
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-
|
|
13
|
+
date: 2011-05-05 00:00:00 -04:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|