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.
@@ -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 = 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"]
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
@@ -128,6 +128,7 @@ module BookWorm
128
128
  def query_isbndb(index, value)
129
129
  get(query_base, :query => { :index1 => index,
130
130
  :value1 => value,
131
+ :results => 'prices',
131
132
  :access_key => Configuration.config[:api_key], })
132
133
  end
133
134
 
@@ -1,3 +1,3 @@
1
1
  module BookWorm
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
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
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-03-08 00:00:00 -05:00
13
+ date: 2011-05-05 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency