kosher 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,33 +1,26 @@
1
1
  Kosher
2
2
  ======
3
3
 
4
- Kosher models an offer by a bookseller.
4
+ Kosher models booksellers' offers.
5
5
 
6
- It knows if the offer is good or bad. It also knows if the offer is
7
- better than another offer. It is somewhat overengineered.
6
+ It knows if an offer is good or bad. It is also able to compare offers.
7
+
8
+ It is somewhat overengineered.
8
9
 
9
10
  ![Booksellers](http://upload.wikimedia.org/wikipedia/commons/thumb/b/b9/Bucharest_booksellers_2.jpg/600px-Bucharest_booksellers_2.jpg)
10
11
 
11
12
  Usage
12
13
  -----
13
14
 
14
- include Kosher
15
-
16
- offer = Offer.new(1234,
17
- Seller.new('ABCDEF',
18
- 'John Doe Books',
19
- 4.8),
20
- Condition.new(1),
21
- Description.new('A fine copy'),
22
- 48,
23
- 1000,
24
- 399,
25
- 'USD',
26
- 'http://bookseller.com/listings/1234'
27
-
28
15
  offer.kosher?
29
16
  => true
17
+ offer.price
18
+ => #<Money cents:1399 currency:EUR>
30
19
 
31
- offer.description = "Withdrawn library book"
32
- offer.kosher?
33
- => false
20
+ another_offer.kosher?
21
+ => true
22
+ another_offer.price
23
+ => #<Money cents:1499 currency:EUR>
24
+
25
+ offer > another_offer
26
+ => true
data/kosher.gemspec CHANGED
@@ -14,8 +14,10 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.rubyforge_project = 'kosher'
16
16
 
17
+ s.add_dependency('json', '~> 1.5.1')
17
18
  s.add_dependency('money', '~> 3.6.1')
18
19
  s.add_development_dependency('rspec', '~> 2.5.0')
20
+ s.add_development_dependency('ruby-debug19', '~> 0.11.6')
19
21
 
20
22
  s.files = `git ls-files`.split("\n")
21
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -0,0 +1,15 @@
1
+ module Kosher
2
+ class Availability < Struct.new(:hours)
3
+ def kosher?
4
+ hours <= threshold
5
+ end
6
+
7
+ def threshold
8
+ @threshold ||= 48
9
+ end
10
+
11
+ def threshold=(hours)
12
+ @threshold = hours
13
+ end
14
+ end
15
+ end
@@ -1,15 +1,19 @@
1
1
  module Kosher
2
- class Condition
3
- def initialize(grade)
4
- @grade = grade
5
- end
6
-
2
+ class Condition < Struct.new(:grade)
7
3
  def kosher?
8
- @grade <= Config.min_condition
4
+ grade <= threshold
9
5
  end
10
6
 
11
7
  def new?
12
- @grade == 1
8
+ grade == 1
9
+ end
10
+
11
+ def threshold
12
+ @threshold ||= 4
13
+ end
14
+
15
+ def threshold=(grade)
16
+ @threshold = grade
13
17
  end
14
18
 
15
19
  def used?
@@ -1,51 +1,43 @@
1
1
  module Kosher
2
- class Description
2
+ class Description < Struct.new(:text)
3
3
  DAMAGED = "\\b(?:missing|torn|broken|split|discard|withdrawn|rent|stain|school|damaged|water)"
4
4
  EXLIB = "(?:e?x|discarded|retired|former|has|have)[\\s._-]*lib"
5
5
  MARKED = "(highlight|hilit|underlin)"
6
6
  MISSING_VOL = "(vols?|volume) only"
7
7
  REVIEW_COPY = "\\b(?:uncorrected|advanced?\\sreview|arc)\\b"
8
8
 
9
- def initialize(string = '')
10
- @description = string
9
+ def damaged?
10
+ matches?(DAMAGED)
11
11
  end
12
12
 
13
- def kosher?
14
- !(damaged? || ex_library? || marked? || missing_volume? || review_copy?)
13
+ def ex_lib?
14
+ matches?(EXLIB) && !matches?(negation_of(EXLIB))
15
15
  end
16
16
 
17
- private
18
-
19
- def damaged?
20
- matches(DAMAGED)
17
+ def kosher?
18
+ !(damaged? || ex_lib? || marked? || missing_volume? || review_copy?)
21
19
  end
22
20
 
23
- def does_not_match(value)
24
- !matches(value)
21
+ def marked?
22
+ matches?(MARKED) && !matches?(negation_of(MARKED))
25
23
  end
26
24
 
27
- def ex_library?
28
- matches(EXLIB) && does_not_match(negation_of(EXLIB))
25
+ def missing_volume?
26
+ matches?(MISSING_VOL)
29
27
  end
30
28
 
31
- def marked?
32
- matches(MARKED) && does_not_match(negation_of(MARKED))
29
+ def review_copy?
30
+ matches?(REVIEW_COPY)
33
31
  end
34
32
 
35
- def matches(value)
36
- @description.match(Regexp.new(value, true))
37
- end
33
+ private
38
34
 
39
- def missing_volume?
40
- matches(MISSING_VOL)
35
+ def matches?(value)
36
+ !!text.match(Regexp.new(value, true))
41
37
  end
42
38
 
43
39
  def negation_of(value)
44
40
  "(?:no|not an?)\\s+#{value}"
45
41
  end
46
-
47
- def review_copy?
48
- matches(REVIEW_COPY)
49
- end
50
42
  end
51
43
  end
@@ -0,0 +1,11 @@
1
+ module Kosher
2
+ class Item < Struct.new(:cents, :currency, :condition, :description)
3
+ def kosher?
4
+ condition.kosher? && description.kosher?
5
+ end
6
+
7
+ def price
8
+ Money.new(cents, currency)
9
+ end
10
+ end
11
+ end
data/lib/kosher/offer.rb CHANGED
@@ -1,45 +1,30 @@
1
- require 'money'
2
-
3
1
  module Kosher
4
- class Offer < Struct.new(
5
- :id,
6
- :seller,
7
- :condition,
8
- :description,
9
- :hours_shipped,
10
- :price_in_cents,
11
- :shipping_in_cents,
12
- :currency,
13
- :url)
14
-
2
+ class Offer < Struct.new(:id, :url, :item, :seller, :shipping)
15
3
  include Comparable
16
4
 
17
- def <=>(another)
18
- if self.kosher? != another.kosher?
5
+ def <=>(other)
6
+ if self.kosher? != other.kosher?
19
7
  self.kosher? ? 1 : -1
20
8
  else
21
- -(self.final_price.exchange_to(Config.base_currency) <=> another.final_price.exchange_to(Config.base_currency))
9
+ currency = base_currency
10
+ -(self.price.exchange_to(currency) <=> other.price.exchange_to(currency))
22
11
  end
23
12
  end
24
13
 
25
- def available?
26
- hours_shipped.to_i <= Config.max_hours_shipped
14
+ def base_currency
15
+ @base_currency ||= 'EUR'
27
16
  end
28
17
 
29
- def final_price
30
- price + shipping
18
+ def base_currency=(currency)
19
+ @base_currency = currency
31
20
  end
32
21
 
33
22
  def kosher?
34
- condition.kosher? && seller.kosher? && description.kosher? && available?
23
+ item.kosher? && seller.kosher? && shipping.kosher?
35
24
  end
36
25
 
37
26
  def price
38
- Money.new(price_in_cents, currency)
39
- end
40
-
41
- def shipping
42
- Money.new(shipping_in_cents.to_i, currency)
27
+ item.price + shipping.cost
43
28
  end
44
29
  end
45
30
  end
data/lib/kosher/seller.rb CHANGED
@@ -1,11 +1,27 @@
1
1
  module Kosher
2
2
  class Seller < Struct.new(:id, :name, :rating)
3
+ def blacklist
4
+ @blacklist ||= []
5
+ end
6
+
7
+ def blacklist=(ids)
8
+ @blacklist = ids
9
+ end
10
+
3
11
  def blacklisted?
4
- Config.blacklist.include?(id)
12
+ blacklist.include? id
5
13
  end
6
14
 
7
15
  def kosher?
8
- !blacklisted? && (rating.to_f == 0.0 || rating >= Config.min_rating)
16
+ !blacklisted? && (rating.to_f == 0.0 || rating >= threshold)
17
+ end
18
+
19
+ def threshold
20
+ @threshold ||= 4.8
21
+ end
22
+
23
+ def threshold=(rating)
24
+ @threshold = rating
9
25
  end
10
26
  end
11
27
  end
@@ -0,0 +1,15 @@
1
+ module Kosher
2
+ class Shipping < Struct.new(:cents, :currency, :availability)
3
+ def free?
4
+ cents.to_i == 0
5
+ end
6
+
7
+ def kosher?
8
+ availability.kosher?
9
+ end
10
+
11
+ def cost
12
+ Money.new(cents.to_i, currency)
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module Kosher
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/kosher.rb CHANGED
@@ -1,5 +1,10 @@
1
+ require 'json'
2
+ require 'money'
3
+
4
+ require 'kosher/availability'
1
5
  require 'kosher/condition'
2
- require 'kosher/config'
3
6
  require 'kosher/description'
7
+ require 'kosher/item'
4
8
  require 'kosher/offer'
5
9
  require 'kosher/seller'
10
+ require 'kosher/shipping'
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module Kosher
4
+ describe Availability do
5
+ before do
6
+ @availability = Availability.new
7
+ end
8
+
9
+ describe "#kosher?" do
10
+ before do
11
+ @availability.threshold = 48
12
+ end
13
+
14
+ context "when available within threshold" do
15
+ it "returns true" do
16
+ @availability.hours = 48
17
+ @availability.should be_kosher
18
+ end
19
+ end
20
+
21
+ context "when not available within threshold" do
22
+ it "returns false" do
23
+ @availability.hours = 96
24
+ @availability.should_not be_kosher
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,17 +2,27 @@ require 'spec_helper'
2
2
 
3
3
  module Kosher
4
4
  describe Condition do
5
+ before do
6
+ @condition = Condition.new
7
+ end
8
+
5
9
  describe "#kosher?" do
6
10
  before do
7
- Config.min_condition = 1
11
+ @condition.threshold = 4
8
12
  end
9
13
 
10
- it "returns true if condition is equal to or better than minimum condition" do
11
- Condition.new(1).should be_kosher
14
+ context "when grade within threshold" do
15
+ it "returns true" do
16
+ @condition.grade = 4
17
+ @condition.should be_kosher
18
+ end
12
19
  end
13
20
 
14
- it "returns false if condition is less than minimum condition" do
15
- Condition.new(2).should_not be_kosher
21
+ context "when grade not within threshold" do
22
+ it "returns false" do
23
+ @condition.grade = 5
24
+ @condition.should_not be_kosher
25
+ end
16
26
  end
17
27
  end
18
28
  end
@@ -2,46 +2,78 @@ require 'spec_helper'
2
2
 
3
3
  module Kosher
4
4
  describe Description do
5
- it "validates a blank description" do
6
- Description.new('').should be_kosher
5
+ before do
6
+ @description = Description.new
7
7
  end
8
8
 
9
- it "validates a non-blank description" do
10
- Description.new('foo').should be_kosher
11
- end
9
+ describe "#kosher?" do
10
+ it "validates a blank description" do
11
+ @description.text = ''
12
+ @description.should be_kosher
13
+ end
12
14
 
13
- it "does not validate advance review copies" do
14
- Description.new('Uncorrected review copy').should_not be_kosher
15
- Description.new('arc').should_not be_kosher
16
- Description.new('arc.').should_not be_kosher
15
+ it "validates a non-blank description" do
16
+ @description.text = 'foo'
17
+ @description.should be_kosher
18
+ end
17
19
 
18
- Description.new('marc').should be_kosher
19
- end
20
+ it "does not validate advance review copies" do
21
+ @description.text = 'Uncorrected review copy'
22
+ @description.should_not be_kosher
20
23
 
21
- it "does not validate marked books" do
22
- Description.new('Some highlighting').should_not be_kosher
23
- Description.new('Underlining.').should_not be_kosher
24
- Description.new('Good. Hiliting.').should_not be_kosher
24
+ @description.text = 'arc'
25
+ @description.should_not be_kosher
25
26
 
26
- Description.new('No highlighting.').should be_kosher
27
- end
27
+ @description.text = 'arc.'
28
+ @description.should_not be_kosher
28
29
 
29
- it "does not validate books with missing volumes" do
30
- Description.new('First vol only.').should_not be_kosher
31
- end
30
+ @description.text = 'marc'
31
+ @description.should be_kosher
32
+ end
32
33
 
33
- it "does not validate damaged or worn books" do
34
- Description.new('Different').should be_kosher
35
- Description.new('Rental').should_not be_kosher
36
- Description.new('Torn pages').should_not be_kosher
37
- end
34
+ it "does not validate marked books" do
35
+ @description.text = 'Some highlighting'
36
+ @description.should_not be_kosher
37
+
38
+ @description.text = 'Underlining.'
39
+ @description.should_not be_kosher
40
+
41
+ @description.text = 'Good. Hiliting.'
42
+ @description.should_not be_kosher
43
+
44
+ @description.text = 'No highlighting.'
45
+ @description.should be_kosher
46
+ end
47
+
48
+ it "does not validate books with missing volumes" do
49
+ @description.text = 'First vol only.'
50
+ @description.should_not be_kosher
51
+ end
52
+
53
+ it "does not validate damaged or worn books" do
54
+ @description.text = 'Different'
55
+ @description.should be_kosher
56
+
57
+ @description.text = 'Rental'
58
+ @description.should_not be_kosher
59
+
60
+ @description.text = 'Torn pages'
61
+ @description.should_not be_kosher
62
+ end
63
+
64
+ it "does not validate withdrawn library copies" do
65
+ @description.text = 'xlib'
66
+ @description.should_not be_kosher
67
+
68
+ @description.text = 'ex-library'
69
+ @description.should_not be_kosher
38
70
 
39
- it "does not validate withdrawn library copies" do
40
- Description.new('xlib').should_not be_kosher
41
- Description.new('ex-library').should_not be_kosher
42
- Description.new('retired library copy').should_not be_kosher
71
+ @description.text = 'retired library copy'
72
+ @description.should_not be_kosher
43
73
 
44
- Description.new('Not an ex-library').should be_kosher
74
+ @description.text = 'Not an ex-library'
75
+ @description.should be_kosher
76
+ end
45
77
  end
46
78
  end
47
79
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module Kosher
4
+ describe Item do
5
+ before do
6
+ @item = Item.new
7
+ end
8
+
9
+ describe "#kosher?" do
10
+ context "when condition is kosher" do
11
+ before do
12
+ @item.condition = Condition.new(1)
13
+ end
14
+
15
+ context "when description is kosher" do
16
+ before do
17
+ @item.description = Description.new('')
18
+ end
19
+
20
+ it "returns true" do
21
+ @item.should be_kosher
22
+ end
23
+ end
24
+
25
+ context "when description is not kosher" do
26
+ before do
27
+ @item.description = Description.new('Withdrawn library book')
28
+ end
29
+
30
+ it "returns false" do
31
+ @item.should_not be_kosher
32
+ end
33
+ end
34
+ end
35
+
36
+ context "when condition is not kosher" do
37
+ before do
38
+ @item.condition = Condition.new(5)
39
+ end
40
+
41
+ it "returns false" do
42
+ @item.should_not be_kosher
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -2,173 +2,177 @@ require 'spec_helper'
2
2
 
3
3
  module Kosher
4
4
  describe Offer do
5
- let(:offer) { Offer.new }
5
+ before do
6
+ @offer = Offer.new
7
+ @offer.item = Item.new
8
+ @offer.seller = Seller.new
9
+ @offer.shipping = Shipping.new
10
+ end
6
11
 
7
12
  describe "#kosher?" do
8
- describe "when condition is kosher" do
13
+ context "when item is kosher" do
9
14
  before do
10
- offer.condition = Condition.new(1)
15
+ @offer.item.stub!(:kosher?).and_return(true)
11
16
  end
12
17
 
13
- describe "when seller is kosher" do
18
+ context "when seller is kosher" do
14
19
  before do
15
- offer.seller = Seller.new
20
+ @offer.seller.stub!(:kosher?).and_return(true)
16
21
  end
17
22
 
18
- describe "when description is kosher" do
23
+ context "when shipping is kosher" do
19
24
  before do
20
- offer.description = Description.new
21
- end
22
-
23
- describe "when offer ships now" do
24
- it "returns true" do
25
- offer.should be_kosher
26
- end
25
+ @offer.shipping.stub!(:kosher?).and_return(true)
27
26
  end
28
27
 
29
- describe "when offer does not ship now" do
30
- before do
31
- offer.hours_shipped = 72
32
- end
33
-
34
- it "returns false" do
35
- offer.should_not be_kosher
36
- end
28
+ it "returns true" do
29
+ @offer.should be_kosher
37
30
  end
38
31
  end
39
32
 
40
- describe "when description is not kosher" do
33
+ context "when shipping is not kosher" do
41
34
  before do
42
- offer.description = Description.new('Withdrawn library book')
35
+ @offer.shipping.stub!(:kosher?).and_return(false)
43
36
  end
44
37
 
45
38
  it "returns false" do
46
- offer.should_not be_kosher
39
+ @offer.should_not be_kosher
47
40
  end
48
41
  end
49
42
  end
50
43
 
51
- describe "when seller is not kosher" do
44
+ context "when seller is not kosher" do
52
45
  before do
53
- offer.seller = Seller.new('foo', 'bar', 4.0)
46
+ @offer.seller.stub!(:kosher?).and_return(false)
54
47
  end
55
48
 
56
49
  it "returns false" do
57
- offer.should_not be_kosher
50
+ @offer.should_not be_kosher
58
51
  end
59
52
  end
60
53
  end
61
54
 
62
- describe "when condition is not kosher" do
55
+ context "when item is not kosher" do
63
56
  before do
64
- offer.condition = Condition.new(5)
65
- end
66
-
67
- it "returns false" do
68
- offer.should_not be_kosher
69
- end
70
- end
71
- end
72
-
73
- describe "#available?" do
74
- before do
75
- Config.max_hours_shipped = 48
76
- end
77
-
78
- describe "when offer is expected to ship on time" do
79
- it "returns true" do
80
- offer.hours_shipped = 48
81
- offer.should be_available
57
+ @offer.item.stub!(:kosher?).and_return(false)
82
58
  end
83
- end
84
59
 
85
- describe "when offer is not expected to ship on time" do
86
60
  it "returns false" do
87
- offer.hours_shipped = 96
88
- offer.should_not be_available
61
+ @offer.should_not be_kosher
89
62
  end
90
63
  end
91
64
  end
92
65
 
93
66
  describe "#price" do
94
- it "returns the price" do
95
- offer.price_in_cents = 100
96
- offer.currency = 'USD'
67
+ it "sum of item price and shipping cost" do
68
+ @offer.item.cents = 1000
69
+ @offer.item.currency = 'EUR'
70
+
71
+ @offer.shipping.cents = 399
72
+ @offer.shipping.currency = 'EUR'
97
73
 
98
- offer.price.should be_kind_of Money
99
- offer.price.format.should eql '$1.00'
74
+ @offer.price.cents.should eql 1399
75
+ @offer.price.currency.iso_code.should eql 'EUR'
100
76
  end
101
77
  end
102
78
 
103
79
  describe "#<=>" do
104
80
  before do
105
- offer.condition = Condition.new(1)
106
- offer.seller = Seller.new
107
- offer.description = Description.new
108
- offer.price_in_cents = 100
109
- offer.currency = 'EUR'
110
- @another_offer = offer.dup
81
+ @another_offer = Offer.new
111
82
  end
112
83
 
113
84
  context "when kosher" do
114
- it "is greater than a non-kosher offer" do
115
- @another_offer.condition = Condition.new(5)
116
- offer.should be_kosher
117
- @another_offer.should_not be_kosher
85
+ before do
86
+ @offer.stub!(:kosher?).and_return(true)
87
+ end
118
88
 
119
- offer.should be > @another_offer
89
+ it "is greater than a non-kosher offer" do
90
+ @another_offer.stub!(:kosher?).and_return(false)
91
+ @offer.should be > @another_offer
120
92
  end
121
93
 
122
- context "when the other offer is kosher too" do
123
- it "is greater than another kosher offer with a higher price" do
124
- @another_offer.price_in_cents = 200
94
+ context "when the other offer is kosher as well" do
95
+ before do
96
+ @offer.stub!(:price).and_return(Money.new(100, 'EUR'))
97
+ @another_offer.stub!(:kosher?).and_return(true)
98
+ end
99
+
100
+ context "when it has a lower price" do
101
+ before do
102
+ @another_offer.stub!(:price).and_return(Money.new(150, 'EUR'))
103
+ end
125
104
 
126
- offer.should be > @another_offer
105
+ it "is greater than other offer" do
106
+ @offer.should be > @another_offer
107
+ end
127
108
  end
128
109
 
129
- it "is equal to another kosher offer with an equal price" do
130
- offer.should be == @another_offer
110
+ context "when the prices are equal" do
111
+ before do
112
+ @another_offer.stub!(:price).and_return(Money.new(100, 'EUR'))
113
+ end
114
+
115
+ it "is equal to the other offer" do
116
+ @offer.should <=> @another_offer
117
+ end
131
118
  end
132
119
 
133
- it "is less than another kosher offer with a lower price" do
134
- @another_offer.price_in_cents = 50
120
+ context "when it has a higher price" do
121
+ before do
122
+ @another_offer.stub!(:price).and_return(Money.new(50, 'EUR'))
123
+ end
135
124
 
136
- offer.should be < @another_offer
125
+ it "is less than the other offer" do
126
+ @offer.should be < @another_offer
127
+ end
137
128
  end
138
129
  end
139
130
  end
140
131
 
141
132
  context "when not kosher" do
142
133
  before do
143
- offer.condition = Condition.new(5)
134
+ @offer.stub!(:kosher?).and_return(false)
144
135
  end
145
136
 
146
137
  it "is less than a kosher offer" do
147
- offer.should_not be_kosher
148
- @another_offer.should be_kosher
149
-
150
- offer.should be < @another_offer
138
+ @another_offer.stub!(:kosher?).and_return(true)
139
+ @offer.should be < @another_offer
151
140
  end
152
141
 
153
142
  context "when the other offer is not kosher either" do
154
143
  before do
155
- @another_offer.condition = Condition.new(5)
144
+ @offer.stub!(:price).and_return(Money.new(100, 'EUR'))
145
+ @another_offer.stub!(:kosher?).and_return(false)
156
146
  end
157
147
 
158
- it "is greater than another unkosher offer with a higher price" do
159
- @another_offer.price_in_cents = 200
148
+ context "when it has a higher price" do
149
+ before do
150
+ @another_offer.stub!(:price).and_return(Money.new(150, 'EUR'))
151
+ end
160
152
 
161
- offer.should be > @another_offer
153
+ it "is greater than the other offer" do
154
+ @offer.should > @another_offer
155
+ end
162
156
  end
163
157
 
164
- it "is equal to another unkosher offer with an equal price" do
165
- offer.should be == @another_offer
158
+ context "when the prices are equal" do
159
+ before do
160
+ @another_offer.stub!(:price).and_return(Money.new(100, 'EUR'))
161
+ end
162
+
163
+ it "is equal to the other offer" do
164
+ @offer.should <=> @another_offer
165
+ end
166
166
  end
167
167
 
168
- it "is less than another unkosher offer with a lower price" do
169
- @another_offer.price_in_cents = 50
168
+ context "when it has a lower price" do
169
+ before do
170
+ @another_offer.stub!(:price).and_return(Money.new(50, 'EUR'))
171
+ end
170
172
 
171
- offer.should be < @another_offer
173
+ it "is less than the other offer" do
174
+ @offer.should < @another_offer
175
+ end
172
176
  end
173
177
  end
174
178
  end
@@ -3,54 +3,59 @@ require 'spec_helper'
3
3
  module Kosher
4
4
  describe Seller do
5
5
  before do
6
- Config.blacklist = nil
6
+ @seller = Seller.new
7
+ end
8
+
9
+ describe "#blacklist" do
10
+ it "defaults to an empty array" do
11
+ @seller.blacklist.should eql []
12
+ end
7
13
  end
8
14
 
9
15
  describe "#blacklisted?" do
10
16
  before do
11
- Config.blacklist = ['foo']
17
+ @seller.blacklist = ['foo']
12
18
  end
13
19
 
14
20
  it "returns true if the seller is blacklisted" do
15
- Seller.new('foo').should be_blacklisted
21
+ @seller.id = 'foo'
22
+ @seller.should be_blacklisted
16
23
  end
17
24
 
18
25
  it "returns false if the seller is not blacklisted" do
19
- Seller.new('bar').should_not be_blacklisted
26
+ @seller.id = 'bar'
27
+ @seller.should_not be_blacklisted
20
28
  end
21
29
  end
22
30
 
23
31
  describe "#kosher?" do
24
32
  before do
25
- Config.min_rating = 4.8
33
+ @seller.threshold = 4.8
26
34
  end
27
35
 
28
- it "returns true if seller's average rating is 0.0" do
29
- seller = Seller.new('foo', 'bar', 0.0)
30
- seller.should be_kosher
36
+ it "returns true if rating is 0.0" do
37
+ @seller.rating = 0.0
38
+ @seller.should be_kosher
31
39
  end
32
40
 
33
- it "returns true if seller's average rating is nil" do
34
- seller = Seller.new
35
- seller.should be_kosher
41
+ it "returns true if rating is nil" do
42
+ @seller.should be_kosher
36
43
  end
37
44
 
38
- it "returns true if seller's average rating is equal to or above the min average rating" do
39
- seller = Seller.new('foo', 'bar', 4.8)
40
- seller.should be_kosher
45
+ it "returns true if rating is within threshold" do
46
+ @seller.rating = 4.8
47
+ @seller.should be_kosher
41
48
  end
42
49
 
43
- it "returns false if sellers' average rating is below the min average rating" do
44
- seller = Seller.new('foo', 'bar', 4.7)
45
- seller.should_not be_kosher
50
+ it "returns false if rating is not within threshold" do
51
+ @seller.rating = 4.7
52
+ @seller.should_not be_kosher
46
53
  end
47
54
 
48
55
  it "returns false if seller is blacklisted" do
49
- seller = Seller.new('foo', 'bar', 5.0)
50
- seller.should be_kosher
51
-
52
- Config.blacklist = [seller.id]
53
- seller.should_not be_kosher
56
+ @seller.id = ['foo']
57
+ @seller.blacklist = [@seller.id]
58
+ @seller.should_not be_kosher
54
59
  end
55
60
  end
56
61
  end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ module Kosher
4
+ describe Shipping do
5
+ before do
6
+ @shipping = Shipping.new
7
+ end
8
+
9
+ describe "#free?" do
10
+ context "when shipping costs 0" do
11
+ it "returns true" do
12
+ @shipping.cents = 0
13
+ @shipping.should be_free
14
+ end
15
+ end
16
+
17
+ context "when shipping costs nil" do
18
+ it "returns true" do
19
+ @shipping.cents = nil
20
+ @shipping.should be_free
21
+ end
22
+ end
23
+
24
+ context "when shipping is not free" do
25
+ it "returns false" do
26
+ @shipping.cents = 1
27
+ @shipping.should_not be_free
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#kosher?" do
33
+ context "when available" do
34
+ it "returns true" do
35
+ @shipping.availability = Availability.new(0)
36
+ @shipping.should be_kosher
37
+ end
38
+ end
39
+
40
+ context "when not available" do
41
+ it "returns false" do
42
+ @shipping.availability = Availability.new(96)
43
+ @shipping.should_not be_kosher
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "#cost" do
49
+ it "returns 0 if no cents given" do
50
+ @shipping.cents = nil
51
+ @shipping.cost.cents.should eql 0
52
+ end
53
+ end
54
+ end
55
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'rspec'
4
+ require 'ruby-debug'
4
5
 
5
6
  require File.expand_path('../../lib/kosher', __FILE__)
6
7
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.2.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paper Cavalier
@@ -14,27 +14,49 @@ date: 2011-03-09 00:00:00 +00:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
- name: money
17
+ name: json
18
18
  prerelease: false
19
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: 3.6.1
24
+ version: 1.5.1
25
25
  type: :runtime
26
26
  version_requirements: *id001
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec
28
+ name: money
29
29
  prerelease: false
30
30
  requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 3.6.1
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
31
42
  none: false
32
43
  requirements:
33
44
  - - ~>
34
45
  - !ruby/object:Gem::Version
35
46
  version: 2.5.0
36
47
  type: :development
37
- version_requirements: *id002
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: ruby-debug19
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: 0.11.6
58
+ type: :development
59
+ version_requirements: *id004
38
60
  description: Kosher wraps Amazon in a loving embrace.
39
61
  email: code@papercavalier.com
40
62
  executables: []
@@ -51,17 +73,21 @@ files:
51
73
  - Rakefile
52
74
  - kosher.gemspec
53
75
  - lib/kosher.rb
76
+ - lib/kosher/availability.rb
54
77
  - lib/kosher/condition.rb
55
- - lib/kosher/config.rb
56
78
  - lib/kosher/description.rb
79
+ - lib/kosher/item.rb
57
80
  - lib/kosher/offer.rb
58
81
  - lib/kosher/seller.rb
82
+ - lib/kosher/shipping.rb
59
83
  - lib/kosher/version.rb
84
+ - spec/kosher/availability_spec.rb
60
85
  - spec/kosher/condition_spec.rb
61
- - spec/kosher/config_spec.rb
62
86
  - spec/kosher/description_spec.rb
87
+ - spec/kosher/item_spec.rb
63
88
  - spec/kosher/offer_spec.rb
64
89
  - spec/kosher/seller_spec.rb
90
+ - spec/kosher/shipping_spec.rb
65
91
  - spec/spec_helper.rb
66
92
  has_rdoc: true
67
93
  homepage: https://rubygems.org/gems/kosher
@@ -92,9 +118,11 @@ signing_key:
92
118
  specification_version: 3
93
119
  summary: Wraps Amazon in a loving embrace.
94
120
  test_files:
121
+ - spec/kosher/availability_spec.rb
95
122
  - spec/kosher/condition_spec.rb
96
- - spec/kosher/config_spec.rb
97
123
  - spec/kosher/description_spec.rb
124
+ - spec/kosher/item_spec.rb
98
125
  - spec/kosher/offer_spec.rb
99
126
  - spec/kosher/seller_spec.rb
127
+ - spec/kosher/shipping_spec.rb
100
128
  - spec/spec_helper.rb
data/lib/kosher/config.rb DELETED
@@ -1,45 +0,0 @@
1
- module Kosher
2
- module Config
3
- extend self
4
-
5
- def base_currency
6
- @base_currency ||= 'EUR'
7
- end
8
-
9
- def base_currency=(code)
10
- @base_currency = code
11
- end
12
-
13
- def blacklist
14
- @blacklist ||= []
15
- end
16
-
17
- def blacklist=(seller_ids)
18
- @blacklist = seller_ids
19
- end
20
-
21
- def max_hours_shipped
22
- @max_hours_shipped ||= 48
23
- end
24
-
25
- def max_hours_shipped=(hours)
26
- @max_hours_shipped = hours
27
- end
28
-
29
- def min_rating
30
- @min_rating ||= 4.8
31
- end
32
-
33
- def min_rating=(rating)
34
- @min_rating = rating
35
- end
36
-
37
- def min_condition
38
- @min_condition ||= 4
39
- end
40
-
41
- def min_condition=(grade)
42
- @min_condition = grade
43
- end
44
- end
45
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Kosher
4
- describe Config do
5
- describe ".base_currency" do
6
- it "defaults to EUR" do
7
- Config.base_currency = nil
8
- Config.base_currency.should eql 'EUR'
9
- end
10
- end
11
-
12
- describe ".blacklist" do
13
- it "defaults to an empty array" do
14
- Config.blacklist = nil
15
- Config.blacklist.should eql []
16
- end
17
- end
18
-
19
- describe ".max_hours_shipped" do
20
- it "defaults to 48" do
21
- Config.max_hours_shipped = nil
22
- Config.max_hours_shipped.should eql 48
23
- end
24
- end
25
-
26
- describe ".min_rating" do
27
- it "defaults to 4.8" do
28
- Config.min_rating = nil
29
- Config.min_rating.should eql 4.8
30
- end
31
- end
32
-
33
- describe ".min_condition" do
34
- it "defaults to 4" do
35
- Config.min_condition = nil
36
- Config.min_condition.should eql 4
37
- end
38
- end
39
- end
40
- end