kosher 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'http://rubygems.org'
2
2
  gemspec
3
- gem 'rake'
4
3
  gem 'pry' unless ENV['CI']
data/kosher.gemspec CHANGED
@@ -9,14 +9,12 @@ 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 things.}
13
- s.description = %q{I filter things.}
12
+ s.summary = %q{A filter}
14
13
 
15
14
  {
16
- 'activemodel' => '~> 3.1',
17
15
  'certainty' => '~> 0.2',
18
16
  'money' => '~> 3.7',
19
- 'structure' => '~> 0.20'
17
+ 'structure' => '~> 0.22'
20
18
  }.each do |lib, version|
21
19
  s.add_runtime_dependency lib, version
22
20
  end
data/lib/kosher.rb CHANGED
@@ -1,28 +1,8 @@
1
- require 'active_model'
2
1
  require 'certainty'
3
2
  require 'money'
4
3
  require 'structure'
5
4
 
6
5
  class Structure
7
- class InvalidRecord < StandardError
8
- def initialize(record)
9
- super record.errors.full_messages.join(', ')
10
- end
11
- end
12
-
13
- include ActiveModel::Conversion
14
- include ActiveModel::Validations
15
- extend ActiveModel::Naming
16
-
17
- def persisted?
18
- false
19
- end
20
-
21
- private
22
-
23
- def validate!
24
- raise InvalidRecord.new(self) if invalid?
25
- end
26
6
  end
27
7
 
28
8
  module Kosher
data/lib/kosher/offer.rb CHANGED
@@ -2,14 +2,14 @@ module Kosher
2
2
  class Offer < Structure
3
3
  include Comparable
4
4
 
5
- key :id, String
6
- key :condition, Condition
7
- key :seller, Seller
5
+ key :kosher, Boolean
6
+ key :new, Boolean
8
7
  key :shipping, Shipping
8
+ key :seller
9
9
  key :unit, Unit
10
- key :venue, String
11
10
 
12
- validates_presence_of :condition, :seller, :shipping, :unit, :venue
11
+ alias kosher? kosher
12
+ alias new? new
13
13
 
14
14
  def <=>(other)
15
15
  if kosher? != other.kosher?
@@ -19,13 +19,8 @@ module Kosher
19
19
  end
20
20
  end
21
21
 
22
- def kosher?
23
- validate!
24
- [seller, shipping, condition].all?(&:kosher?)
25
- end
26
-
27
22
  def price
28
- unit.price + shipping.price
23
+ unit.price + shipping.cost
29
24
  end
30
25
  end
31
26
  end
@@ -1,15 +1,10 @@
1
1
  module Kosher
2
2
  class Shipping < Structure
3
- include Filter
4
- include Price
3
+ key :cents, Integer
4
+ key :currency
5
5
 
6
- key :available, Boolean
7
-
8
- validates_presence_of :available
9
-
10
- def available?
11
- validate!
12
- available
6
+ def cost
7
+ Money.new(cents, currency)
13
8
  end
14
9
  end
15
10
  end
data/lib/kosher/unit.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  module Kosher
2
2
  class Unit < Structure
3
- include Price
3
+ key :cents, Integer
4
+ key :currency, String
4
5
 
5
- key :quantity, Integer, 1
6
+ def price
7
+ Money.new(cents, currency)
8
+ end
6
9
  end
7
10
  end
@@ -1,3 +1,3 @@
1
1
  module Kosher
2
- VERSION = '0.15.0'
2
+ VERSION = '0.16.0'
3
3
  end
data/test/kosher_test.rb CHANGED
@@ -1,51 +1,21 @@
1
- # encoding: UTF-8
2
1
  require 'minitest/autorun'
3
-
4
2
  require_relative '../lib/kosher'
5
-
6
3
  begin
7
4
  require 'pry'
8
- rescue LoadError
5
+ rescue LoadError
9
6
  end
10
7
 
11
8
  include Kosher
12
9
 
13
10
  class TestKosher < MiniTest::Unit::TestCase
14
- def test_money
15
- unit = Unit.new( :cents => '1000',
16
- :currency => 'EUR')
17
- shipping = Shipping.new(:available => true,
18
- :cents => '300',
19
- :currency => 'EUR')
20
- offer = Offer.new( :shipping => shipping,
21
- :unit => unit)
22
-
23
- assert_equal '10,00 €', unit.price.format
24
- assert_equal '3,00 €', shipping.price.format
25
- assert_equal '13,00 €', offer.price.format
26
- end
27
-
28
- def test_validation
29
- assert_raises(Structure::InvalidRecord) { Condition.new.kosher? }
30
- condition = Condition.new(:grade => 1)
31
- assert condition.kosher?
32
-
33
- assert_raises(Structure::InvalidRecord) { Shipping.new.kosher? }
34
- shipping = Shipping.new(:available => true,
35
- :cents => 100,
36
- :currency => 'USD')
37
- assert shipping.kosher?
11
+ def test_prices
12
+ unit = Unit.new(cents: 100, currency: 'USD')
13
+ assert_equal '$1.00', unit.price.format
38
14
 
39
- assert_raises(Structure::InvalidRecord) { Seller.new.kosher? }
40
- seller = Seller.new(:name => 'John Doe')
41
- assert seller.kosher?
15
+ ship = Shipping.new(cents: 100, currency: 'USD')
16
+ assert_equal '$1.00', ship.cost.format
42
17
 
43
- assert_raises(Structure::InvalidRecord) { Offer.new.kosher? }
44
- offer = Offer.new(:condition => condition,
45
- :shipping => shipping,
46
- :seller => seller,
47
- :unit => Unit.new,
48
- :venue => 'Amazon.com')
49
- assert offer.kosher?
18
+ offer = Offer.new(unit: unit, shipping: ship)
19
+ assert_equal '$2.00', offer.price.format
50
20
  end
51
21
  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.15.0
4
+ version: 0.16.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-07 00:00:00.000000000Z
12
+ date: 2011-10-27 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: activemodel
16
- requirement: &70296149797340 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.1'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: *70296149797340
25
14
  - !ruby/object:Gem::Dependency
26
15
  name: certainty
27
- requirement: &70296149796480 !ruby/object:Gem::Requirement
16
+ requirement: &70249913314080 !ruby/object:Gem::Requirement
28
17
  none: false
29
18
  requirements:
30
19
  - - ~>
@@ -32,10 +21,10 @@ dependencies:
32
21
  version: '0.2'
33
22
  type: :runtime
34
23
  prerelease: false
35
- version_requirements: *70296149796480
24
+ version_requirements: *70249913314080
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: money
38
- requirement: &70296149795640 !ruby/object:Gem::Requirement
27
+ requirement: &70249913313320 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ~>
@@ -43,19 +32,19 @@ dependencies:
43
32
  version: '3.7'
44
33
  type: :runtime
45
34
  prerelease: false
46
- version_requirements: *70296149795640
35
+ version_requirements: *70249913313320
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: structure
49
- requirement: &70296149794680 !ruby/object:Gem::Requirement
38
+ requirement: &70249913312280 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
53
42
  - !ruby/object:Gem::Version
54
- version: '0.20'
43
+ version: '0.22'
55
44
  type: :runtime
56
45
  prerelease: false
57
- version_requirements: *70296149794680
58
- description: I filter things.
46
+ version_requirements: *70249913312280
47
+ description:
59
48
  email: code@papercavalier.com
60
49
  executables: []
61
50
  extensions: []
@@ -69,11 +58,7 @@ files:
69
58
  - Rakefile
70
59
  - kosher.gemspec
71
60
  - lib/kosher.rb
72
- - lib/kosher/condition.rb
73
- - lib/kosher/filter.rb
74
61
  - lib/kosher/offer.rb
75
- - lib/kosher/price.rb
76
- - lib/kosher/seller.rb
77
62
  - lib/kosher/shipping.rb
78
63
  - lib/kosher/unit.rb
79
64
  - lib/kosher/version.rb
@@ -90,23 +75,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
75
  - - ! '>='
91
76
  - !ruby/object:Gem::Version
92
77
  version: '0'
93
- segments:
94
- - 0
95
- hash: -3818355639004243263
96
78
  required_rubygems_version: !ruby/object:Gem::Requirement
97
79
  none: false
98
80
  requirements:
99
81
  - - ! '>='
100
82
  - !ruby/object:Gem::Version
101
83
  version: '0'
102
- segments:
103
- - 0
104
- hash: -3818355639004243263
105
84
  requirements: []
106
85
  rubyforge_project:
107
- rubygems_version: 1.8.6
86
+ rubygems_version: 1.8.10
108
87
  signing_key:
109
88
  specification_version: 3
110
- summary: I filter things.
89
+ summary: A filter
111
90
  test_files:
112
91
  - test/kosher_test.rb
@@ -1,18 +0,0 @@
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 DELETED
@@ -1,12 +0,0 @@
1
- module Kosher
2
- module Filter
3
- def self.included(base)
4
- base.key :kosher, Boolean, true
5
- end
6
-
7
- def kosher?
8
- validate!
9
- kosher
10
- end
11
- end
12
- end
data/lib/kosher/price.rb DELETED
@@ -1,17 +0,0 @@
1
- module Kosher
2
- module Price
3
- def self.included(base)
4
- base.key :cents, Integer
5
- base.key :currency, String
6
-
7
- base.validates_presence_of :currency
8
- base.validates_numericality_of :cents, :greater_than => 0
9
- end
10
-
11
- def price
12
- validate!
13
-
14
- Money.new(cents, currency)
15
- end
16
- end
17
- end
data/lib/kosher/seller.rb DELETED
@@ -1,11 +0,0 @@
1
- module Kosher
2
- class Seller < Structure
3
- include Filter
4
-
5
- key :id, String
6
- key :name, String
7
- key :rating, Float
8
-
9
- validates_presence_of :name
10
- end
11
- end