kosher 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/kosher/condition.rb +6 -12
- data/lib/kosher/item.rb +18 -15
- data/lib/kosher/version.rb +1 -1
- data/spec/kosher/algorithm_spec.rb +1 -1
- data/spec/kosher/condition_spec.rb +10 -10
- data/spec/kosher/description_spec.rb +19 -19
- data/spec/kosher/item_spec.rb +2 -1
- data/spec/kosher/offer_spec.rb +1 -1
- data/spec/kosher/seller_spec.rb +2 -2
- data/spec/support/vcr.rb +1 -1
- metadata +1 -1
data/lib/kosher/condition.rb
CHANGED
@@ -2,18 +2,12 @@ module Kosher
|
|
2
2
|
class Condition < Struct.new(:in_words)
|
3
3
|
def to_i
|
4
4
|
case in_words
|
5
|
-
when 'new'
|
6
|
-
|
7
|
-
when '
|
8
|
-
|
9
|
-
when '
|
10
|
-
|
11
|
-
when 'good'
|
12
|
-
4
|
13
|
-
when 'acceptable'
|
14
|
-
5
|
15
|
-
else
|
16
|
-
6
|
5
|
+
when 'new' then 1
|
6
|
+
when 'mint' then 2
|
7
|
+
when 'verygood' then 3
|
8
|
+
when 'good' then 4
|
9
|
+
when 'acceptable' then 5
|
10
|
+
else 6
|
17
11
|
end
|
18
12
|
end
|
19
13
|
|
data/lib/kosher/item.rb
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
module Kosher
|
2
|
-
class Item < Struct.new(:asin, :offers)
|
2
|
+
class Item < Struct.new(:asin, :offers, :sales_rank)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
class << self
|
5
|
+
def build(doc)
|
6
|
+
asin = doc['ASIN']
|
7
|
+
sales_rank = doc['SalesRank'].to_i
|
8
|
+
offers = build_offers(doc['Offers']['Offer'])
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
+
new(asin, offers, sales_rank)
|
11
|
+
end
|
10
12
|
|
11
|
-
|
13
|
+
private
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
+
def build_offers(offers)
|
16
|
+
[offers].flatten.compact.map do |offer|
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
# Senify Yen because Ruby Money says so
|
19
|
+
price = offer['OfferListing']['Price']
|
20
|
+
if price['CurrencyCode'] == 'JPY'
|
21
|
+
price['Amount'] = price['Amount'].to_i * 100
|
22
|
+
end
|
21
23
|
|
22
|
-
|
24
|
+
Offer.build(offer)
|
25
|
+
end
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
data/lib/kosher/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Kosher
|
4
4
|
describe Condition do
|
@@ -8,23 +8,23 @@ module Kosher
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "casts as integer" do
|
11
|
-
this(
|
12
|
-
this(
|
13
|
-
this(
|
14
|
-
this(
|
15
|
-
this(
|
11
|
+
this('new').should eql 1
|
12
|
+
this('mint').should eql 2
|
13
|
+
this('verygood').should eql 3
|
14
|
+
this('good').should eql 4
|
15
|
+
this('acceptable').should eql 5
|
16
16
|
end
|
17
17
|
|
18
18
|
it "casts unrecognized conditions as 6" do
|
19
|
-
this(
|
19
|
+
this('refurbished').should eql 6
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#kosher?" do
|
24
24
|
it "returns true if condition is good or better" do
|
25
|
-
Condition.new(
|
26
|
-
Condition.new(
|
27
|
-
Condition.new(
|
25
|
+
Condition.new('verygood').should be_kosher
|
26
|
+
Condition.new('good').should be_kosher
|
27
|
+
Condition.new('acceptable').should_not be_kosher
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
module Kosher
|
4
4
|
describe Description do
|
@@ -11,45 +11,45 @@ module Kosher
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "validates a blank description" do
|
14
|
-
this(
|
14
|
+
this('').should be_kosher
|
15
15
|
end
|
16
16
|
|
17
17
|
it "validates a non-blank description" do
|
18
|
-
this(
|
18
|
+
this('foo').should be_kosher
|
19
19
|
end
|
20
20
|
|
21
21
|
it "does not validate advance review copies" do
|
22
|
-
this(
|
23
|
-
this(
|
24
|
-
this(
|
22
|
+
this('Uncorrected review copy').should_not be_kosher
|
23
|
+
this('arc').should_not be_kosher
|
24
|
+
this('arc.').should_not be_kosher
|
25
25
|
|
26
|
-
this(
|
26
|
+
this('marc').should be_kosher
|
27
27
|
end
|
28
28
|
|
29
29
|
it "does not validate marked books" do
|
30
|
-
this(
|
31
|
-
this(
|
32
|
-
this(
|
30
|
+
this('Some highlighting').should_not be_kosher
|
31
|
+
this('Underlining.').should_not be_kosher
|
32
|
+
this('Good. Hiliting.').should_not be_kosher
|
33
33
|
|
34
|
-
this(
|
34
|
+
this('No highlighting.').should be_kosher
|
35
35
|
end
|
36
36
|
|
37
37
|
it "does not validate books with missing volumes" do
|
38
|
-
this(
|
38
|
+
this('First vol only.').should_not be_kosher
|
39
39
|
end
|
40
40
|
|
41
41
|
it "does not validate damaged or worn books" do
|
42
|
-
this(
|
43
|
-
this(
|
44
|
-
this(
|
42
|
+
this('Different').should be_kosher
|
43
|
+
this('Rental').should_not be_kosher
|
44
|
+
this('Torn pages').should_not be_kosher
|
45
45
|
end
|
46
46
|
|
47
47
|
it "does not validate withdrawn library copies" do
|
48
|
-
this(
|
49
|
-
this(
|
50
|
-
this(
|
48
|
+
this('xlib').should_not be_kosher
|
49
|
+
this('ex-library').should_not be_kosher
|
50
|
+
this('retired library copy').should_not be_kosher
|
51
51
|
|
52
|
-
this(
|
52
|
+
this('Not an ex-library').should be_kosher
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
data/spec/kosher/item_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
module Kosher
|
4
4
|
describe Item do
|
5
5
|
describe ".build" do
|
6
|
-
use_vcr_cassette '0143105825'
|
6
|
+
use_vcr_cassette '0143105825'
|
7
7
|
|
8
8
|
let(:asin) { '0143105825' }
|
9
9
|
|
@@ -24,6 +24,7 @@ module Kosher
|
|
24
24
|
it "should build an item" do
|
25
25
|
item.should be_a Item
|
26
26
|
item.asin.should eql asin
|
27
|
+
item.sales_rank.should be > 0
|
27
28
|
end
|
28
29
|
|
29
30
|
it "should build the offers of an item" do
|
data/spec/kosher/offer_spec.rb
CHANGED
data/spec/kosher/seller_spec.rb
CHANGED
data/spec/support/vcr.rb
CHANGED
@@ -4,7 +4,7 @@ VCR.config do |c|
|
|
4
4
|
c.cassette_library_dir = "#{File.dirname(__FILE__)}/../fixtures/cassette_library"
|
5
5
|
c.stub_with :webmock
|
6
6
|
c.ignore_localhost = true
|
7
|
-
c.default_cassette_options = { :record => :new_episodes }
|
7
|
+
c.default_cassette_options = { :record => :new_episodes, :match_requests_on => [:host] }
|
8
8
|
end
|
9
9
|
|
10
10
|
RSpec.configure do |config|
|