kosher 0.1.2 → 0.1.3

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.
@@ -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
- 1
7
- when 'mint'
8
- 2
9
- when 'verygood'
10
- 3
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
- def self.build(doc)
5
- asin = doc['ASIN']
6
- offers = build_offers(doc['Offers']['Offer'])
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
- new(asin, offers)
9
- end
10
+ new(asin, offers, sales_rank)
11
+ end
10
12
 
11
- private
13
+ private
12
14
 
13
- def self.build_offers(offers)
14
- [offers].flatten.compact.map do |offer|
15
+ def build_offers(offers)
16
+ [offers].flatten.compact.map do |offer|
15
17
 
16
- # Senify Yen because Ruby Money says so
17
- price = offer['OfferListing']['Price']
18
- if price['CurrencyCode'] == 'JPY'
19
- price['Amount'] = price['Amount'].to_i * 100
20
- end
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
- Offer.build(offer)
24
+ Offer.build(offer)
25
+ end
23
26
  end
24
27
  end
25
28
  end
@@ -1,3 +1,3 @@
1
1
  module Kosher
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module Kosher
4
4
  describe Algorithm do
@@ -1,4 +1,4 @@
1
- require "spec_helper"
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("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
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("refurbished").should eql 6
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("verygood").should be_kosher
26
- Condition.new("good").should be_kosher
27
- Condition.new("acceptable").should_not be_kosher
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 "spec_helper"
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("").should be_kosher
14
+ this('').should be_kosher
15
15
  end
16
16
 
17
17
  it "validates a non-blank description" do
18
- this("foo").should be_kosher
18
+ this('foo').should be_kosher
19
19
  end
20
20
 
21
21
  it "does not validate advance review copies" do
22
- this("Uncorrected review copy").should_not be_kosher
23
- this("arc").should_not be_kosher
24
- this("arc.").should_not be_kosher
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("marc").should be_kosher
26
+ this('marc').should be_kosher
27
27
  end
28
28
 
29
29
  it "does not validate marked books" do
30
- this("Some highlighting").should_not be_kosher
31
- this("Underlining.").should_not be_kosher
32
- this("Good. Hiliting.").should_not be_kosher
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("No highlighting.").should be_kosher
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("First vol only.").should_not be_kosher
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("Different").should be_kosher
43
- this("Rental").should_not be_kosher
44
- this("Torn pages").should_not be_kosher
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("xlib").should_not be_kosher
49
- this("ex-library").should_not be_kosher
50
- this("retired library copy").should_not be_kosher
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("Not an ex-library").should be_kosher
52
+ this('Not an ex-library').should be_kosher
53
53
  end
54
54
  end
55
55
  end
@@ -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', :match_requests_on => [:host]
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
@@ -5,7 +5,7 @@ module Kosher
5
5
  let(:offer) { Fabricate(:offer) }
6
6
 
7
7
  describe ".build" do
8
- use_vcr_cassette '0143105825', :match_requests_on => [:host]
8
+ use_vcr_cassette '0143105825'
9
9
 
10
10
  let(:asin) { '0143105825' }
11
11
 
@@ -1,9 +1,9 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  module Kosher
4
4
  describe Seller do
5
5
  describe ".build" do
6
- use_vcr_cassette "0143105825", :match_requests_on => [:host]
6
+ use_vcr_cassette '0143105825'
7
7
 
8
8
  let(:asin) { '0143105825' }
9
9
 
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|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paper Cavalier