kosher 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/kosher.gemspec +3 -6
- data/lib/kosher/item.rb +1 -7
- data/lib/kosher/offer.rb +1 -3
- data/lib/kosher/price.rb +13 -0
- data/lib/kosher/shipping.rb +2 -9
- data/lib/kosher/version.rb +1 -1
- data/lib/kosher.rb +2 -6
- data/spec/kosher/item_spec.rb +0 -10
- data/spec/kosher/offer_spec.rb +2 -5
- data/spec/kosher/price_spec.rb +16 -0
- data/spec/kosher/seller_spec.rb +2 -2
- data/spec/kosher/shipping_spec.rb +2 -12
- data/spec/spec_helper.rb +1 -4
- metadata +17 -33
- data/lib/kosher/author.rb +0 -8
- data/lib/kosher/book.rb +0 -39
- data/lib/kosher/image.rb +0 -9
- data/spec/kosher/book_spec.rb +0 -76
data/kosher.gemspec
CHANGED
@@ -9,20 +9,17 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.authors = ['Paper Cavalier']
|
10
10
|
s.email = 'code@papercavalier.com'
|
11
11
|
s.homepage = 'https://rubygems.org/gems/kosher'
|
12
|
-
s.summary = %q{An overengineered
|
13
|
-
s.description = %q{Kosher
|
14
|
-
|
15
|
-
s.rubyforge_project = 'kosher'
|
12
|
+
s.summary = %q{An overengineered abstraction of book trading}
|
13
|
+
s.description = %q{Kosher abstracts online book trading into a set of models.}
|
16
14
|
|
17
15
|
{
|
18
16
|
'rspec' => '~> 2.6',
|
19
|
-
'ruby-debug19' => '~> 0.11.6'
|
20
17
|
}.each do |lib, version|
|
21
18
|
s.add_development_dependency lib, version
|
22
19
|
end
|
23
20
|
|
24
21
|
{
|
25
|
-
'money' => '~> 3.
|
22
|
+
'money' => '~> 3.7.1',
|
26
23
|
'structure' => '~> 0.7.1'
|
27
24
|
}.each do |lib, version|
|
28
25
|
s.add_runtime_dependency lib, version
|
data/lib/kosher/item.rb
CHANGED
@@ -4,19 +4,13 @@ module Kosher
|
|
4
4
|
#
|
5
5
|
# An item has a price, quantity, condition, and description.
|
6
6
|
class Item < Structure
|
7
|
-
key :cents, :type => Integer
|
8
|
-
key :currency
|
9
7
|
key :quantity, :type => Integer
|
8
|
+
has_one :price
|
10
9
|
has_one :condition
|
11
10
|
has_one :description
|
12
11
|
|
13
12
|
def kosher?
|
14
13
|
condition.kosher? && description.kosher?
|
15
14
|
end
|
16
|
-
|
17
|
-
def price
|
18
|
-
raise TypeError, "Can't render money" unless cents
|
19
|
-
Money.new(cents, currency)
|
20
|
-
end
|
21
15
|
end
|
22
16
|
end
|
data/lib/kosher/offer.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Kosher
|
2
2
|
|
3
3
|
# An offer.
|
4
|
-
#
|
5
|
-
# This is an actual item offered on a particular venue by a seller.
|
6
4
|
class Offer < Structure
|
7
5
|
include Comparable
|
8
6
|
|
@@ -33,7 +31,7 @@ module Kosher
|
|
33
31
|
|
34
32
|
# The total price of an offer.
|
35
33
|
def price
|
36
|
-
item.price + shipping.cost
|
34
|
+
item.price.to_money + shipping.cost.to_money
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/kosher/price.rb
ADDED
data/lib/kosher/shipping.rb
CHANGED
@@ -3,24 +3,17 @@ module Kosher
|
|
3
3
|
#
|
4
4
|
# Shipping costs something (or nothing) and is subject to availability.
|
5
5
|
class Shipping < Structure
|
6
|
-
|
7
|
-
key :currency
|
6
|
+
has_one :cost
|
8
7
|
has_one :availability
|
9
8
|
|
10
9
|
# Returns whether the item ships for free.
|
11
10
|
def free?
|
12
|
-
cents == 0
|
11
|
+
cost.cents == 0
|
13
12
|
end
|
14
13
|
|
15
14
|
# Returns true if the item is available to ship.
|
16
15
|
def kosher?
|
17
16
|
availability.kosher?
|
18
17
|
end
|
19
|
-
|
20
|
-
# The shipping cost.
|
21
|
-
def cost
|
22
|
-
raise TypeError, "Can't render money" unless cents
|
23
|
-
Money.new(cents, currency)
|
24
|
-
end
|
25
18
|
end
|
26
19
|
end
|
data/lib/kosher/version.rb
CHANGED
data/lib/kosher.rb
CHANGED
@@ -9,25 +9,21 @@ require 'structure/json'
|
|
9
9
|
require 'kosher/threshold'
|
10
10
|
|
11
11
|
# Require the models.
|
12
|
-
require 'kosher/author'
|
13
12
|
require 'kosher/availability'
|
14
|
-
require 'kosher/book'
|
15
13
|
require 'kosher/condition'
|
16
14
|
require 'kosher/description'
|
17
|
-
require 'kosher/image'
|
18
15
|
require 'kosher/item'
|
19
16
|
require 'kosher/location'
|
20
17
|
require 'kosher/offer'
|
18
|
+
require 'kosher/price'
|
21
19
|
require 'kosher/seller'
|
22
20
|
require 'kosher/shipping'
|
23
21
|
require 'kosher/venue'
|
24
22
|
|
25
23
|
module Kosher
|
26
24
|
class << self
|
27
|
-
attr_writer :seller_blacklist
|
28
|
-
|
29
25
|
def seller_blacklist
|
30
|
-
@seller_blacklist ||=
|
26
|
+
@seller_blacklist ||= Array.new
|
31
27
|
end
|
32
28
|
end
|
33
29
|
|
data/spec/kosher/item_spec.rb
CHANGED
data/spec/kosher/offer_spec.rb
CHANGED
@@ -65,11 +65,8 @@ module Kosher
|
|
65
65
|
|
66
66
|
describe "#price" do
|
67
67
|
it "sum of item price and shipping cost" do
|
68
|
-
@offer.item.cents
|
69
|
-
@offer.
|
70
|
-
|
71
|
-
@offer.shipping.cents = 399
|
72
|
-
@offer.shipping.currency = 'EUR'
|
68
|
+
@offer.item.price = Price.new(cents: 1000, currency: 'EUR')
|
69
|
+
@offer.shipping.cost = Price.new(cents: 399, currency: 'EUR')
|
73
70
|
|
74
71
|
@offer.price.cents.should eql 1399
|
75
72
|
@offer.price.currency.iso_code.should eql 'EUR'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Kosher
|
4
|
+
describe Price do
|
5
|
+
describe "#to_money" do
|
6
|
+
it "returns a Money object" do
|
7
|
+
price = Price.new(:cents => 100, :currency => 'USD')
|
8
|
+
price.to_money.should be_a Money
|
9
|
+
end
|
10
|
+
|
11
|
+
it "raises a type error if cents is nil" do
|
12
|
+
expect { Price.new.to_money }.to raise_error TypeError
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/kosher/seller_spec.rb
CHANGED
@@ -8,7 +8,7 @@ module Kosher
|
|
8
8
|
|
9
9
|
describe "#blacklisted?" do
|
10
10
|
before do
|
11
|
-
Kosher.seller_blacklist
|
11
|
+
Kosher.seller_blacklist << 'foo'
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns true if the seller is blacklisted" do
|
@@ -48,7 +48,7 @@ module Kosher
|
|
48
48
|
|
49
49
|
it "returns false if seller is blacklisted" do
|
50
50
|
@seller.id = ['foo']
|
51
|
-
Kosher.seller_blacklist
|
51
|
+
Kosher.seller_blacklist << @seller.id
|
52
52
|
@seller.should_not be_kosher
|
53
53
|
end
|
54
54
|
end
|
@@ -9,14 +9,14 @@ module Kosher
|
|
9
9
|
describe "#free?" do
|
10
10
|
context "when shipping costs 0" do
|
11
11
|
it "returns true" do
|
12
|
-
@shipping.
|
12
|
+
@shipping.cost = Price.new(cents: 0)
|
13
13
|
@shipping.should be_free
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
context "when shipping is not free" do
|
18
18
|
it "returns false" do
|
19
|
-
@shipping.
|
19
|
+
@shipping.cost = Price.new(cents: 1)
|
20
20
|
@shipping.should_not be_free
|
21
21
|
end
|
22
22
|
end
|
@@ -37,15 +37,5 @@ module Kosher
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
40
|
-
|
41
|
-
describe "#cost" do
|
42
|
-
context "when no cents are specified" do
|
43
|
-
it "raises an error" do
|
44
|
-
expect do
|
45
|
-
@shipping.cost
|
46
|
-
end.to raise_error TypeError
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
40
|
end
|
51
41
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'bundler/setup'
|
3
3
|
require 'rspec'
|
4
|
-
require 'ruby-debug'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
5
|
+
trequire File.expand_path('../../lib/kosher', __FILE__)
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 7
|
8
|
+
- 0
|
9
|
+
version: 0.7.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Paper Cavalier
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-06-
|
17
|
+
date: 2011-06-20 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,39 +31,25 @@ dependencies:
|
|
31
31
|
version: "2.6"
|
32
32
|
type: :development
|
33
33
|
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: ruby-debug19
|
36
|
-
prerelease: false
|
37
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
-
none: false
|
39
|
-
requirements:
|
40
|
-
- - ~>
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
- 11
|
45
|
-
- 6
|
46
|
-
version: 0.11.6
|
47
|
-
type: :development
|
48
|
-
version_requirements: *id002
|
49
34
|
- !ruby/object:Gem::Dependency
|
50
35
|
name: money
|
51
36
|
prerelease: false
|
52
|
-
requirement: &
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
53
38
|
none: false
|
54
39
|
requirements:
|
55
40
|
- - ~>
|
56
41
|
- !ruby/object:Gem::Version
|
57
42
|
segments:
|
58
43
|
- 3
|
59
|
-
-
|
60
|
-
|
44
|
+
- 7
|
45
|
+
- 1
|
46
|
+
version: 3.7.1
|
61
47
|
type: :runtime
|
62
|
-
version_requirements: *
|
48
|
+
version_requirements: *id002
|
63
49
|
- !ruby/object:Gem::Dependency
|
64
50
|
name: structure
|
65
51
|
prerelease: false
|
66
|
-
requirement: &
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
67
53
|
none: false
|
68
54
|
requirements:
|
69
55
|
- - ~>
|
@@ -74,8 +60,8 @@ dependencies:
|
|
74
60
|
- 1
|
75
61
|
version: 0.7.1
|
76
62
|
type: :runtime
|
77
|
-
version_requirements: *
|
78
|
-
description: Kosher
|
63
|
+
version_requirements: *id003
|
64
|
+
description: Kosher abstracts online book trading into a set of models.
|
79
65
|
email: code@papercavalier.com
|
80
66
|
executables: []
|
81
67
|
|
@@ -91,27 +77,25 @@ files:
|
|
91
77
|
- Rakefile
|
92
78
|
- kosher.gemspec
|
93
79
|
- lib/kosher.rb
|
94
|
-
- lib/kosher/author.rb
|
95
80
|
- lib/kosher/availability.rb
|
96
|
-
- lib/kosher/book.rb
|
97
81
|
- lib/kosher/condition.rb
|
98
82
|
- lib/kosher/description.rb
|
99
|
-
- lib/kosher/image.rb
|
100
83
|
- lib/kosher/item.rb
|
101
84
|
- lib/kosher/location.rb
|
102
85
|
- lib/kosher/offer.rb
|
86
|
+
- lib/kosher/price.rb
|
103
87
|
- lib/kosher/seller.rb
|
104
88
|
- lib/kosher/shipping.rb
|
105
89
|
- lib/kosher/threshold.rb
|
106
90
|
- lib/kosher/venue.rb
|
107
91
|
- lib/kosher/version.rb
|
108
92
|
- spec/kosher/availability_spec.rb
|
109
|
-
- spec/kosher/book_spec.rb
|
110
93
|
- spec/kosher/condition_spec.rb
|
111
94
|
- spec/kosher/description_spec.rb
|
112
95
|
- spec/kosher/item_spec.rb
|
113
96
|
- spec/kosher/location_spec.rb
|
114
97
|
- spec/kosher/offer_spec.rb
|
98
|
+
- spec/kosher/price_spec.rb
|
115
99
|
- spec/kosher/seller_spec.rb
|
116
100
|
- spec/kosher/shipping_spec.rb
|
117
101
|
- spec/kosher/venue_spec.rb
|
@@ -144,19 +128,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
128
|
version: "0"
|
145
129
|
requirements: []
|
146
130
|
|
147
|
-
rubyforge_project:
|
131
|
+
rubyforge_project:
|
148
132
|
rubygems_version: 1.3.7
|
149
133
|
signing_key:
|
150
134
|
specification_version: 3
|
151
|
-
summary: An overengineered
|
135
|
+
summary: An overengineered abstraction of book trading
|
152
136
|
test_files:
|
153
137
|
- spec/kosher/availability_spec.rb
|
154
|
-
- spec/kosher/book_spec.rb
|
155
138
|
- spec/kosher/condition_spec.rb
|
156
139
|
- spec/kosher/description_spec.rb
|
157
140
|
- spec/kosher/item_spec.rb
|
158
141
|
- spec/kosher/location_spec.rb
|
159
142
|
- spec/kosher/offer_spec.rb
|
143
|
+
- spec/kosher/price_spec.rb
|
160
144
|
- spec/kosher/seller_spec.rb
|
161
145
|
- spec/kosher/shipping_spec.rb
|
162
146
|
- spec/kosher/venue_spec.rb
|
data/lib/kosher/author.rb
DELETED
data/lib/kosher/book.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Kosher
|
2
|
-
|
3
|
-
# A book.
|
4
|
-
#
|
5
|
-
# A book is sold on many venues and has many offers through those venues.
|
6
|
-
class Book < Structure
|
7
|
-
key :asin
|
8
|
-
key :edition
|
9
|
-
key :format
|
10
|
-
key :images, :type => Hash
|
11
|
-
key :isbn
|
12
|
-
key :pages, :type => Integer
|
13
|
-
key :published_in, :type => Integer
|
14
|
-
key :publisher
|
15
|
-
key :title
|
16
|
-
key :volumes, :type => Integer
|
17
|
-
has_many :other_editions
|
18
|
-
has_many :authors
|
19
|
-
has_many :offers
|
20
|
-
has_many :similar_books
|
21
|
-
|
22
|
-
# The best kosher offer.
|
23
|
-
#
|
24
|
-
# Returns nil if there are no (kosher) offers.
|
25
|
-
def best_kosher_offer
|
26
|
-
offer = offers.sort.first
|
27
|
-
offer && offer.kosher? ? offer : nil
|
28
|
-
end
|
29
|
-
|
30
|
-
# A full bibliographic description of the book, as in:
|
31
|
-
#
|
32
|
-
# Chronicle Books, 1991. Hardcover. 1st edition. 2 volumes. 1200 pages.
|
33
|
-
#
|
34
|
-
# Missing attributes are omitted.
|
35
|
-
def description
|
36
|
-
# TODO
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
data/lib/kosher/image.rb
DELETED
data/spec/kosher/book_spec.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Kosher
|
4
|
-
describe Book do
|
5
|
-
describe "#best_kosher_offer" do
|
6
|
-
before do
|
7
|
-
@book = Book.new
|
8
|
-
|
9
|
-
@offer1 = Offer.new
|
10
|
-
@offer2 = Offer.new
|
11
|
-
end
|
12
|
-
|
13
|
-
context "when there are more than one kosher offers" do
|
14
|
-
before do
|
15
|
-
@offer1.stub!(:kosher?).and_return(true)
|
16
|
-
@offer1.stub!(:price).and_return(Money.new(200, 'EUR'))
|
17
|
-
@book.offers << @offer1
|
18
|
-
|
19
|
-
@offer2.stub!(:kosher?).and_return(true)
|
20
|
-
@offer2.stub!(:price).and_return(Money.new(100, 'EUR'))
|
21
|
-
@book.offers << @offer2
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns the kosher offer with the lowest price" do
|
25
|
-
@book.best_kosher_offer.should eql @offer2
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context "when there is one kosher and one unkosher offer" do
|
30
|
-
before do
|
31
|
-
@offer1.stub!(:kosher?).and_return(true)
|
32
|
-
@offer1.stub!(:price).and_return(Money.new(200, 'EUR'))
|
33
|
-
@book.offers << @offer1
|
34
|
-
|
35
|
-
@offer2.stub!(:kosher?).and_return(false)
|
36
|
-
@offer2.stub!(:price).and_return(Money.new(100, 'EUR'))
|
37
|
-
@book.offers << @offer2
|
38
|
-
end
|
39
|
-
|
40
|
-
it "returns the kosher offer" do
|
41
|
-
@book.best_kosher_offer.should eql @offer1
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when there is one kosher offer" do
|
46
|
-
before do
|
47
|
-
@offer1.stub!(:kosher?).and_return(true)
|
48
|
-
@offer1.stub!(:price).and_return(Money.new(100, 'EUR'))
|
49
|
-
@book.offers << @offer1
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns the kosher offer" do
|
53
|
-
@book.best_kosher_offer.should eql @offer1
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when there is one unkosher offer" do
|
58
|
-
before do
|
59
|
-
@offer1.stub!(:kosher?).and_return(false)
|
60
|
-
@offer1.stub!(:price).and_return(Money.new(100, 'EUR'))
|
61
|
-
@book.offers << @offer1
|
62
|
-
end
|
63
|
-
|
64
|
-
it "returns nil" do
|
65
|
-
@book.best_kosher_offer.should be_nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
context "when there are no offers" do
|
70
|
-
it "returns nil" do
|
71
|
-
@book.best_kosher_offer.should be_nil
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|