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 +0 -1
- data/kosher.gemspec +2 -4
- data/lib/kosher.rb +0 -20
- data/lib/kosher/offer.rb +6 -11
- data/lib/kosher/shipping.rb +4 -9
- data/lib/kosher/unit.rb +5 -2
- data/lib/kosher/version.rb +1 -1
- data/test/kosher_test.rb +8 -38
- metadata +12 -33
- data/lib/kosher/condition.rb +0 -18
- data/lib/kosher/filter.rb +0 -12
- data/lib/kosher/price.rb +0 -17
- data/lib/kosher/seller.rb +0 -11
data/Gemfile
CHANGED
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{
|
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.
|
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 :
|
6
|
-
key :
|
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
|
-
|
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.
|
23
|
+
unit.price + shipping.cost
|
29
24
|
end
|
30
25
|
end
|
31
26
|
end
|
data/lib/kosher/shipping.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
module Kosher
|
2
2
|
class Shipping < Structure
|
3
|
-
|
4
|
-
|
3
|
+
key :cents, Integer
|
4
|
+
key :currency
|
5
5
|
|
6
|
-
|
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
data/lib/kosher/version.rb
CHANGED
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
|
-
|
5
|
+
rescue LoadError
|
9
6
|
end
|
10
7
|
|
11
8
|
include Kosher
|
12
9
|
|
13
10
|
class TestKosher < MiniTest::Unit::TestCase
|
14
|
-
def
|
15
|
-
unit
|
16
|
-
|
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
|
-
|
40
|
-
|
41
|
-
assert seller.kosher?
|
15
|
+
ship = Shipping.new(cents: 100, currency: 'USD')
|
16
|
+
assert_equal '$1.00', ship.cost.format
|
42
17
|
|
43
|
-
|
44
|
-
|
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.
|
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-
|
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: &
|
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: *
|
24
|
+
version_requirements: *70249913314080
|
36
25
|
- !ruby/object:Gem::Dependency
|
37
26
|
name: money
|
38
|
-
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: *
|
35
|
+
version_requirements: *70249913313320
|
47
36
|
- !ruby/object:Gem::Dependency
|
48
37
|
name: structure
|
49
|
-
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.
|
43
|
+
version: '0.22'
|
55
44
|
type: :runtime
|
56
45
|
prerelease: false
|
57
|
-
version_requirements: *
|
58
|
-
description:
|
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.
|
86
|
+
rubygems_version: 1.8.10
|
108
87
|
signing_key:
|
109
88
|
specification_version: 3
|
110
|
-
summary:
|
89
|
+
summary: A filter
|
111
90
|
test_files:
|
112
91
|
- test/kosher_test.rb
|
data/lib/kosher/condition.rb
DELETED
@@ -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
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
|