kosher 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  [![travis](http://travis-ci.org/hakanensari/kosher.png)](http://travis-ci.org/hakanensari/kosher)
4
4
 
5
- I filter stuff.
5
+ I filter things.
data/kosher.gemspec CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |s|
9
9
  s.authors = ['Hakan Ensari']
10
10
  s.email = 'code@papercavalier.com'
11
11
  s.homepage = 'https://github.com/hakanensari/kosher'
12
- s.summary = %q{I filter stuff.}
13
- s.description = %q{I filter stuff.}
12
+ s.summary = %q{I filter things.}
13
+ s.description = %q{I filter things.}
14
14
 
15
15
  {
16
- 'activemodel' => '~> 3.0',
16
+ 'activemodel' => '~> 3.1',
17
17
  'certainty' => '~> 0.2',
18
18
  'money' => '~> 3.7',
19
- 'structure' => '~> 0.19'
19
+ 'structure' => '~> 0.20'
20
20
  }.each do |lib, version|
21
21
  s.add_runtime_dependency lib, version
22
22
  end
@@ -0,0 +1,18 @@
1
+ module Kosher
2
+ class Condition < Structure
3
+ include Filter
4
+
5
+ key :grade, Integer
6
+ key :description, String, ''
7
+
8
+ validates_inclusion_of :grade, :in => 1..6
9
+
10
+ def new?
11
+ grade == 1
12
+ end
13
+
14
+ def used?
15
+ grade != 1
16
+ end
17
+ end
18
+ end
data/lib/kosher/filter.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  module Kosher
2
2
  module Filter
3
3
  def self.included(base)
4
- base.key :kosher, Boolean, :default => true
4
+ base.key :kosher, Boolean, true
5
5
  end
6
6
 
7
7
  def kosher?
8
- raise_error_if_invalid
9
-
8
+ validate!
10
9
  kosher
11
10
  end
12
11
  end
data/lib/kosher/offer.rb CHANGED
@@ -1,24 +1,15 @@
1
- require 'kosher/filter'
2
- require 'kosher/price'
3
-
4
- require 'kosher/detail'
5
- require 'kosher/seller'
6
- require 'kosher/shipping'
7
- require 'kosher/unit'
8
- require 'kosher/venue'
9
-
10
1
  module Kosher
11
2
  class Offer < Structure
12
3
  include Comparable
13
4
 
14
- key :id, String
15
- key :detail, Detail
16
- key :seller, Seller
5
+ key :id, String
6
+ key :condition, Condition
7
+ key :seller, Seller
17
8
  key :shipping, Shipping
18
- key :unit, Unit
19
- key :venue_id, Integer
9
+ key :unit, Unit
10
+ key :venue, String
20
11
 
21
- validates_presence_of :detail, :seller, :shipping, :unit, :venue
12
+ validates_presence_of :condition, :seller, :shipping, :unit, :venue
22
13
 
23
14
  def <=>(other)
24
15
  if kosher? != other.kosher?
@@ -29,17 +20,12 @@ module Kosher
29
20
  end
30
21
 
31
22
  def kosher?
32
- raise_error_if_invalid
33
-
34
- [seller, shipping, detail].all?(&:kosher?)
23
+ validate!
24
+ [seller, shipping, condition].all?(&:kosher?)
35
25
  end
36
26
 
37
27
  def price
38
28
  unit.price + shipping.price
39
29
  end
40
-
41
- def venue
42
- Venue.find(venue_id)
43
- end
44
30
  end
45
31
  end
data/lib/kosher/price.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Kosher
2
2
  module Price
3
3
  def self.included(base)
4
- base.key :cents, Integer
4
+ base.key :cents, Integer
5
5
  base.key :currency, String
6
6
 
7
7
  base.validates_presence_of :currency
@@ -9,7 +9,7 @@ module Kosher
9
9
  end
10
10
 
11
11
  def price
12
- raise_error_if_invalid
12
+ validate!
13
13
 
14
14
  Money.new(cents, currency)
15
15
  end
data/lib/kosher/seller.rb CHANGED
@@ -2,8 +2,8 @@ module Kosher
2
2
  class Seller < Structure
3
3
  include Filter
4
4
 
5
- key :id, String
6
- key :name, String
5
+ key :id, String
6
+ key :name, String
7
7
  key :rating, Float
8
8
 
9
9
  validates_presence_of :name
@@ -7,6 +7,9 @@ module Kosher
7
7
 
8
8
  validates_presence_of :available
9
9
 
10
- alias available? available
10
+ def available?
11
+ validate!
12
+ available
13
+ end
11
14
  end
12
15
  end
data/lib/kosher/unit.rb CHANGED
@@ -2,6 +2,6 @@ module Kosher
2
2
  class Unit < Structure
3
3
  include Price
4
4
 
5
- key :quantity, Integer, :default => 1
5
+ key :quantity, Integer, 1
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Kosher
2
- VERSION = '0.14.2'
2
+ VERSION = '0.15.0'
3
3
  end
data/lib/kosher.rb CHANGED
@@ -6,14 +6,13 @@ require 'structure'
6
6
  class Structure
7
7
  class InvalidRecord < StandardError
8
8
  def initialize(record)
9
- msg = record.errors.full_messages.join(', ')
10
- super msg
9
+ super record.errors.full_messages.join(', ')
11
10
  end
12
11
  end
13
12
 
14
13
  include ActiveModel::Conversion
15
14
  include ActiveModel::Validations
16
- extend ActiveModel::Naming
15
+ extend ActiveModel::Naming
17
16
 
18
17
  def persisted?
19
18
  false
@@ -21,9 +20,17 @@ class Structure
21
20
 
22
21
  private
23
22
 
24
- def raise_error_if_invalid
23
+ def validate!
25
24
  raise InvalidRecord.new(self) if invalid?
26
25
  end
27
26
  end
28
27
 
29
- require 'kosher/offer'
28
+ module Kosher
29
+ autoload :Condition, 'kosher/condition'
30
+ autoload :Filter, 'kosher/filter'
31
+ autoload :Offer, 'kosher/offer'
32
+ autoload :Price, 'kosher/price'
33
+ autoload :Seller, 'kosher/seller'
34
+ autoload :Shipping, 'kosher/shipping'
35
+ autoload :Unit, 'kosher/unit'
36
+ end
data/test/kosher_test.rb CHANGED
@@ -11,33 +11,24 @@ end
11
11
  include Kosher
12
12
 
13
13
  class TestKosher < MiniTest::Unit::TestCase
14
- def test_prices
15
- unit = Unit.new(:cents => '1000',
16
- :currency => 'EUR')
17
- assert_equal '10,00 €', unit.price.format
18
-
14
+ def test_money
15
+ unit = Unit.new( :cents => '1000',
16
+ :currency => 'EUR')
19
17
  shipping = Shipping.new(:available => true,
20
18
  :cents => '300',
21
19
  :currency => 'EUR')
22
- assert_equal '3,00 €', shipping.price.format
20
+ offer = Offer.new( :shipping => shipping,
21
+ :unit => unit)
23
22
 
24
- offer = Offer.new(:shipping => shipping,
25
- :unit => unit)
23
+ assert_equal '10,00 €', unit.price.format
24
+ assert_equal '3,00 €', shipping.price.format
26
25
  assert_equal '13,00 €', offer.price.format
27
26
  end
28
27
 
29
- def test_venues
30
- assert_equal 'Amazon.com', Venue.find(1).name
31
- assert_equal 'Amazon.co.uk', Venue.find(2).name
32
-
33
- offer = Offer.new(:venue_id => 1)
34
- assert_equal Venue.find(1), offer.venue
35
- end
36
-
37
28
  def test_validation
38
- assert_raises(Structure::InvalidRecord) { Detail.new.kosher? }
39
- detail = Detail.new(:condition => 1)
40
- assert detail.kosher?
29
+ assert_raises(Structure::InvalidRecord) { Condition.new.kosher? }
30
+ condition = Condition.new(:grade => 1)
31
+ assert condition.kosher?
41
32
 
42
33
  assert_raises(Structure::InvalidRecord) { Shipping.new.kosher? }
43
34
  shipping = Shipping.new(:available => true,
@@ -50,18 +41,11 @@ class TestKosher < MiniTest::Unit::TestCase
50
41
  assert seller.kosher?
51
42
 
52
43
  assert_raises(Structure::InvalidRecord) { Offer.new.kosher? }
53
- offer = Offer.new(:detail => detail,
54
- :shipping => shipping,
55
- :seller => seller,
56
- :unit => Unit.new,
57
- :venue_id => 1)
44
+ offer = Offer.new(:condition => condition,
45
+ :shipping => shipping,
46
+ :seller => seller,
47
+ :unit => Unit.new,
48
+ :venue => 'Amazon.com')
58
49
  assert offer.kosher?
59
50
  end
60
-
61
- def test_venues
62
- assert_kind_of Venue, Venue.first
63
- assert 'Amazon.com', Venue.find(1).name
64
- assert_nil Venue.find(0)
65
- assert_equal 8, Venue.amazon.size
66
- end
67
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kosher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.15.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-01 00:00:00.000000000Z
12
+ date: 2011-09-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70237892025340 !ruby/object:Gem::Requirement
16
+ requirement: &70296149797340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '3.0'
21
+ version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70237892025340
24
+ version_requirements: *70296149797340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: certainty
27
- requirement: &70237892024860 !ruby/object:Gem::Requirement
27
+ requirement: &70296149796480 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.2'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70237892024860
35
+ version_requirements: *70296149796480
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: money
38
- requirement: &70237892024420 !ruby/object:Gem::Requirement
38
+ requirement: &70296149795640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,19 +43,19 @@ dependencies:
43
43
  version: '3.7'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70237892024420
46
+ version_requirements: *70296149795640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: structure
49
- requirement: &70237892023980 !ruby/object:Gem::Requirement
49
+ requirement: &70296149794680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '0.19'
54
+ version: '0.20'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70237892023980
58
- description: I filter stuff.
57
+ version_requirements: *70296149794680
58
+ description: I filter things.
59
59
  email: code@papercavalier.com
60
60
  executables: []
61
61
  extensions: []
@@ -67,17 +67,15 @@ files:
67
67
  - LICENSE
68
68
  - README.md
69
69
  - Rakefile
70
- - data/venues.yml
71
70
  - kosher.gemspec
72
71
  - lib/kosher.rb
73
- - lib/kosher/detail.rb
72
+ - lib/kosher/condition.rb
74
73
  - lib/kosher/filter.rb
75
74
  - lib/kosher/offer.rb
76
75
  - lib/kosher/price.rb
77
76
  - lib/kosher/seller.rb
78
77
  - lib/kosher/shipping.rb
79
78
  - lib/kosher/unit.rb
80
- - lib/kosher/venue.rb
81
79
  - lib/kosher/version.rb
82
80
  - test/kosher_test.rb
83
81
  homepage: https://github.com/hakanensari/kosher
@@ -94,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
92
  version: '0'
95
93
  segments:
96
94
  - 0
97
- hash: 4442667444567861971
95
+ hash: -3818355639004243263
98
96
  required_rubygems_version: !ruby/object:Gem::Requirement
99
97
  none: false
100
98
  requirements:
@@ -103,12 +101,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
101
  version: '0'
104
102
  segments:
105
103
  - 0
106
- hash: 4442667444567861971
104
+ hash: -3818355639004243263
107
105
  requirements: []
108
106
  rubyforge_project:
109
107
  rubygems_version: 1.8.6
110
108
  signing_key:
111
109
  specification_version: 3
112
- summary: I filter stuff.
110
+ summary: I filter things.
113
111
  test_files:
114
112
  - test/kosher_test.rb
data/data/venues.yml DELETED
@@ -1,28 +0,0 @@
1
- ---
2
- - id: 1
3
- name: Amazon.com
4
- country: us
5
- - id: 2
6
- name: Amazon.co.uk
7
- country: uk
8
- - id: 3
9
- name: Amazon.de
10
- country: de
11
- - id: 4
12
- name: Amazon.ca
13
- country: ca
14
- - id: 5
15
- name: Amazon.fr
16
- country: fr
17
- - id: 6
18
- name: Amazon.co.jp
19
- country: jp
20
- - id: 7
21
- name: Amazon.co.jp
22
- country: jp
23
- - id: 8
24
- name: Amazon.cn
25
- country: cn
26
- - id: 9
27
- name: Barnesandnoble.com
28
- country: us
data/lib/kosher/detail.rb DELETED
@@ -1,18 +0,0 @@
1
- module Kosher
2
- class Detail < Structure
3
- include Filter
4
-
5
- key :condition, Integer
6
- key :description, String, :default => ''
7
-
8
- validates_inclusion_of :condition, :in => 1..6
9
-
10
- def new?
11
- condition == 1
12
- end
13
-
14
- def used?
15
- !new?
16
- end
17
- end
18
- end
data/lib/kosher/venue.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'yaml'
2
-
3
- module Kosher
4
- class Venue < Structure
5
- DATA_PATH = File.expand_path("../../../data/venues.yml", __FILE__)
6
-
7
- key :_id, Integer
8
- key :country, String
9
- key :name, String
10
-
11
- class << self
12
- include Enumerable
13
-
14
- def all
15
- @all ||= YAML.load_file(DATA_PATH).map do |hsh|
16
- hsh['_id'] ||= hsh.delete('id')
17
- new(hsh)
18
- end
19
- end
20
-
21
- def amazon
22
- @amazons ||= find_all { |e| e.name.include? 'Amazon' }
23
- end
24
-
25
- def each(&block)
26
- all.each { |item| block.call(item) }
27
- end
28
-
29
- def find(id)
30
- super() { |item| item._id == id }
31
- end
32
- end
33
- end
34
- end