kosher 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,15 +1,11 @@
1
1
  module Kosher
2
2
  class Availability < Struct.new(:hours)
3
- def kosher?
4
- hours <= threshold
5
- end
3
+ include Threshold
6
4
 
7
- def threshold
8
- @threshold ||= 48
9
- end
5
+ THRESHOLD = 48
10
6
 
11
- def threshold=(hours)
12
- @threshold = hours
7
+ def kosher?
8
+ hours <= threshold
13
9
  end
14
10
  end
15
11
  end
@@ -1,5 +1,9 @@
1
1
  module Kosher
2
2
  class Condition < Struct.new(:grade)
3
+ include Threshold
4
+
5
+ THRESHOLD = 4
6
+
3
7
  def kosher?
4
8
  grade <= threshold
5
9
  end
@@ -8,14 +12,6 @@ module Kosher
8
12
  grade == 1
9
13
  end
10
14
 
11
- def threshold
12
- @threshold ||= 4
13
- end
14
-
15
- def threshold=(grade)
16
- @threshold = grade
17
- end
18
-
19
15
  def used?
20
16
  !new?
21
17
  end
data/lib/kosher/seller.rb CHANGED
@@ -1,27 +1,29 @@
1
1
  module Kosher
2
2
  class Seller < Struct.new(:id, :name, :rating, :location)
3
- def blacklist
4
- @blacklist ||= []
3
+ include Threshold
4
+
5
+ THRESHOLD = 4.8
6
+
7
+ class << self
8
+ def blacklist
9
+ @blacklist ||= []
10
+ end
11
+
12
+ def blacklist=(ids)
13
+ @blacklist = ids
14
+ end
5
15
  end
6
16
 
7
- def blacklist=(ids)
8
- @blacklist = ids
17
+ def blacklist
18
+ self.class.blacklist
9
19
  end
10
20
 
11
21
  def blacklisted?
12
- blacklist.include? id
22
+ blacklist.include?(id)
13
23
  end
14
24
 
15
25
  def kosher?
16
26
  !blacklisted? && (rating.to_f == 0.0 || rating >= threshold)
17
27
  end
18
-
19
- def threshold
20
- @threshold ||= 4.8
21
- end
22
-
23
- def threshold=(rating)
24
- @threshold = rating
25
- end
26
28
  end
27
29
  end
@@ -0,0 +1,21 @@
1
+ module Kosher
2
+ module Threshold
3
+ def self.included(klass)
4
+ klass.extend(ClassMethods)
5
+ end
6
+
7
+ def threshold
8
+ self.class.threshold
9
+ end
10
+
11
+ module ClassMethods
12
+ def threshold
13
+ @threshold ||= THRESHOLD
14
+ end
15
+
16
+ def threshold=(value)
17
+ @threshold = value
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Kosher
2
- VERSION = '0.2.11'
2
+ VERSION = '0.2.12'
3
3
  end
data/lib/kosher.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'money'
2
2
 
3
+ require 'kosher/threshold'
4
+
3
5
  require 'kosher/availability'
4
6
  require 'kosher/condition'
5
7
  require 'kosher/description'
@@ -8,7 +8,7 @@ module Kosher
8
8
 
9
9
  describe "#kosher?" do
10
10
  before do
11
- @availability.threshold = 48
11
+ Availability.threshold = 48
12
12
  end
13
13
 
14
14
  context "when available within threshold" do
@@ -8,7 +8,7 @@ module Kosher
8
8
 
9
9
  describe "#kosher?" do
10
10
  before do
11
- @condition.threshold = 4
11
+ Condition.threshold = 4
12
12
  end
13
13
 
14
14
  context "when grade within threshold" do
@@ -14,7 +14,7 @@ module Kosher
14
14
 
15
15
  describe "#blacklisted?" do
16
16
  before do
17
- @seller.blacklist = ['foo']
17
+ Seller.blacklist = ['foo']
18
18
  end
19
19
 
20
20
  it "returns true if the seller is blacklisted" do
@@ -30,7 +30,7 @@ module Kosher
30
30
 
31
31
  describe "#kosher?" do
32
32
  before do
33
- @seller.threshold = 4.8
33
+ Seller.threshold = 4.8
34
34
  end
35
35
 
36
36
  it "returns true if rating is 0.0" do
@@ -54,7 +54,7 @@ module Kosher
54
54
 
55
55
  it "returns false if seller is blacklisted" do
56
56
  @seller.id = ['foo']
57
- @seller.blacklist = [@seller.id]
57
+ Seller.blacklist = [@seller.id]
58
58
  @seller.should_not be_kosher
59
59
  end
60
60
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kosher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.11
5
+ version: 0.2.12
6
6
  platform: ruby
7
7
  authors:
8
8
  - Paper Cavalier
@@ -71,6 +71,7 @@ files:
71
71
  - lib/kosher/seller.rb
72
72
  - lib/kosher/shipping.rb
73
73
  - lib/kosher/snapshot.rb
74
+ - lib/kosher/threshold.rb
74
75
  - lib/kosher/version.rb
75
76
  - spec/kosher/availability_spec.rb
76
77
  - spec/kosher/condition_spec.rb