dry-logic 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/lib/dry/logic/predicates.rb +16 -0
- data/lib/dry/logic/version.rb +1 -1
- data/spec/spec_helper.rb +5 -0
- data/spec/unit/predicates/even_spec.rb +31 -0
- data/spec/unit/predicates/number_spec.rb +37 -0
- data/spec/unit/predicates/odd_spec.rb +31 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e25000a6e80f51337190d6dc64bf1566bdcceafd
|
4
|
+
data.tar.gz: bfd9743a8aa9b6cc7f3bc95788120acfec5b9ee6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb98dba1f9b5c22af3dd9fe729193246cc2df3af90302cce7ab1c5b81d5c5f189192e25673aadbb82c8ac26eabb79054d496328ccbbab1d0b6340be0cccd7624
|
7
|
+
data.tar.gz: 590203f2b2e3788bf3d7e2d5039d445162060e0fa0a2b6978e7f17a33212e7b54fceb1d41e7aafa4ecfcee815a26eaf5756b2cdc68d0b6426f9f335937e2b54d
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/lib/dry/logic/predicates.rb
CHANGED
@@ -56,6 +56,14 @@ module Dry
|
|
56
56
|
input.is_a?(Time)
|
57
57
|
end
|
58
58
|
|
59
|
+
predicate(:number?) do |input|
|
60
|
+
begin
|
61
|
+
true if Float(input)
|
62
|
+
rescue ArgumentError, TypeError
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
59
67
|
predicate(:int?) do |input|
|
60
68
|
input.is_a?(Fixnum)
|
61
69
|
end
|
@@ -80,6 +88,14 @@ module Dry
|
|
80
88
|
input.is_a?(Array)
|
81
89
|
end
|
82
90
|
|
91
|
+
predicate(:odd?) do |input|
|
92
|
+
input.odd?
|
93
|
+
end
|
94
|
+
|
95
|
+
predicate(:even?) do |input|
|
96
|
+
input.even?
|
97
|
+
end
|
98
|
+
|
83
99
|
predicate(:lt?) do |num, input|
|
84
100
|
input < num
|
85
101
|
end
|
data/lib/dry/logic/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'dry/logic/predicates'
|
2
|
+
|
3
|
+
RSpec.describe Dry::Logic::Predicates do
|
4
|
+
describe '#even?' do
|
5
|
+
let(:predicate_name) { :even? }
|
6
|
+
|
7
|
+
context 'when value is an odd int' do
|
8
|
+
let(:arguments_list) do
|
9
|
+
[
|
10
|
+
[13],
|
11
|
+
[1],
|
12
|
+
[1111]
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
it_behaves_like 'a failing predicate'
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with value is an even int' do
|
20
|
+
let(:arguments_list) do
|
21
|
+
[
|
22
|
+
[0],
|
23
|
+
[2],
|
24
|
+
[2222]
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
it_behaves_like 'a passing predicate'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'dry/logic/predicates'
|
2
|
+
|
3
|
+
RSpec.describe Dry::Logic::Predicates do
|
4
|
+
describe '#number?' do
|
5
|
+
let(:predicate_name) { :number? }
|
6
|
+
|
7
|
+
context 'when value is numerical' do
|
8
|
+
let(:arguments_list) do
|
9
|
+
[
|
10
|
+
["34"],
|
11
|
+
["1.000004"],
|
12
|
+
["0"],
|
13
|
+
[4],
|
14
|
+
["-15.24"],
|
15
|
+
[-3.5]
|
16
|
+
]
|
17
|
+
end
|
18
|
+
|
19
|
+
it_behaves_like 'a passing predicate'
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with value is not numerical' do
|
23
|
+
let(:arguments_list) do
|
24
|
+
[
|
25
|
+
[''],
|
26
|
+
["-14px"],
|
27
|
+
["10,150.00"],
|
28
|
+
[nil],
|
29
|
+
[:symbol],
|
30
|
+
[String]
|
31
|
+
]
|
32
|
+
end
|
33
|
+
|
34
|
+
it_behaves_like 'a failing predicate'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'dry/logic/predicates'
|
2
|
+
|
3
|
+
RSpec.describe Dry::Logic::Predicates do
|
4
|
+
describe '#odd?' do
|
5
|
+
let(:predicate_name) { :odd? }
|
6
|
+
|
7
|
+
context 'when value is an odd int' do
|
8
|
+
let(:arguments_list) do
|
9
|
+
[
|
10
|
+
[13],
|
11
|
+
[1],
|
12
|
+
[1111]
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
it_behaves_like 'a passing predicate'
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'with value is an even int' do
|
20
|
+
let(:arguments_list) do
|
21
|
+
[
|
22
|
+
[0],
|
23
|
+
[2],
|
24
|
+
[2222]
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
it_behaves_like 'a failing predicate'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-logic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-container
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- spec/unit/predicates/decimal_spec.rb
|
139
139
|
- spec/unit/predicates/empty_spec.rb
|
140
140
|
- spec/unit/predicates/eql_spec.rb
|
141
|
+
- spec/unit/predicates/even_spec.rb
|
141
142
|
- spec/unit/predicates/exclusion_spec.rb
|
142
143
|
- spec/unit/predicates/false_spec.rb
|
143
144
|
- spec/unit/predicates/filled_spec.rb
|
@@ -153,6 +154,8 @@ files:
|
|
153
154
|
- spec/unit/predicates/max_size_spec.rb
|
154
155
|
- spec/unit/predicates/min_size_spec.rb
|
155
156
|
- spec/unit/predicates/none_spec.rb
|
157
|
+
- spec/unit/predicates/number_spec.rb
|
158
|
+
- spec/unit/predicates/odd_spec.rb
|
156
159
|
- spec/unit/predicates/size_spec.rb
|
157
160
|
- spec/unit/predicates/str_spec.rb
|
158
161
|
- spec/unit/predicates/time_spec.rb
|
@@ -188,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
191
|
version: '0'
|
189
192
|
requirements: []
|
190
193
|
rubyforge_project:
|
191
|
-
rubygems_version: 2.
|
194
|
+
rubygems_version: 2.5.1
|
192
195
|
signing_key:
|
193
196
|
specification_version: 4
|
194
197
|
summary: Predicate logic with rule composition
|
@@ -203,6 +206,7 @@ test_files:
|
|
203
206
|
- spec/unit/predicates/decimal_spec.rb
|
204
207
|
- spec/unit/predicates/empty_spec.rb
|
205
208
|
- spec/unit/predicates/eql_spec.rb
|
209
|
+
- spec/unit/predicates/even_spec.rb
|
206
210
|
- spec/unit/predicates/exclusion_spec.rb
|
207
211
|
- spec/unit/predicates/false_spec.rb
|
208
212
|
- spec/unit/predicates/filled_spec.rb
|
@@ -218,6 +222,8 @@ test_files:
|
|
218
222
|
- spec/unit/predicates/max_size_spec.rb
|
219
223
|
- spec/unit/predicates/min_size_spec.rb
|
220
224
|
- spec/unit/predicates/none_spec.rb
|
225
|
+
- spec/unit/predicates/number_spec.rb
|
226
|
+
- spec/unit/predicates/odd_spec.rb
|
221
227
|
- spec/unit/predicates/size_spec.rb
|
222
228
|
- spec/unit/predicates/str_spec.rb
|
223
229
|
- spec/unit/predicates/time_spec.rb
|