apill 3.0.7 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apill/parameters/filter.rb +19 -1
- data/lib/apill/version.rb +1 -1
- data/spec/apill/resource/processors/filtering_spec.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bb09a75851259a89a82d3d9aff3a5aa05a7f72a
|
4
|
+
data.tar.gz: db6adc23f9d21ce30143c5aa7083af136aed499e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1ca8cda7cf22f3f190b0dd91524ad577b5ddb8da3bbd41c8fedfc289f986ea95be73f00e01acac0e43ba1ac11994111e4832d2d270a1ddb13194a0c19cd051a
|
7
|
+
data.tar.gz: fb581d7be8f0a54863939b990779f55bc968ca65b13ef2e45454ba0b106d1a87c1bb3dadf8fa0929d7291bb66c3362bf6bf153e28703271beed6edd18d8916ba
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Apill
|
2
2
|
class Parameters
|
3
3
|
class Filter
|
4
|
+
NUMERICAL_RANGE = /\A([\d\.]+?)\.\.\.?([\d\.]+?)\z/
|
5
|
+
|
4
6
|
attr_accessor :raw_parameters
|
5
7
|
|
6
8
|
def initialize(raw_parameters)
|
@@ -13,7 +15,7 @@ class Filter
|
|
13
15
|
|
14
16
|
def each_with_object(memoized)
|
15
17
|
compacted_parameters.each do |name, value|
|
16
|
-
memoized = yield name, value, memoized
|
18
|
+
memoized = yield name, format_value(value), memoized
|
17
19
|
end
|
18
20
|
|
19
21
|
memoized
|
@@ -28,6 +30,22 @@ class Filter
|
|
28
30
|
value.nil?
|
29
31
|
end
|
30
32
|
end
|
33
|
+
|
34
|
+
# rubocop:disable Lint/AssignmentInCondition
|
35
|
+
def format_value(value)
|
36
|
+
return value unless value.is_a?(String)
|
37
|
+
|
38
|
+
if range_points = value.match(NUMERICAL_RANGE)
|
39
|
+
exclusive = value.include? '...'
|
40
|
+
starting_point = range_points[1].to_f
|
41
|
+
ending_point = range_points[2].to_f
|
42
|
+
|
43
|
+
Range.new(starting_point, ending_point, exclusive)
|
44
|
+
else
|
45
|
+
value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
# rubocop:enable Lint/AssignmentInCondition
|
31
49
|
end
|
32
50
|
end
|
33
51
|
end
|
data/lib/apill/version.rb
CHANGED
@@ -63,6 +63,23 @@ describe Filtering do
|
|
63
63
|
expect(filtering.processed).to eql 'other_stuffed'
|
64
64
|
end
|
65
65
|
|
66
|
+
it 'can properly format numerical ranges' do
|
67
|
+
filtering = Filtering.new(filtering_resource,
|
68
|
+
'filter' => {
|
69
|
+
'stuff' => '100...200',
|
70
|
+
'other_stuff' => '333.33..888.0',
|
71
|
+
})
|
72
|
+
|
73
|
+
allow(filtering_resource).to receive(:for_stuff).
|
74
|
+
with(100.0...200.0).
|
75
|
+
and_return filtering_resource
|
76
|
+
allow(filtering_resource).to receive(:other_stuff).
|
77
|
+
with(333.33..888.0).
|
78
|
+
and_return 'other_stuffed'
|
79
|
+
|
80
|
+
expect(filtering.processed).to eql 'other_stuffed'
|
81
|
+
end
|
82
|
+
|
66
83
|
it 'can handle objects (eg ActiveRelation) that store their proxy class in klass' do
|
67
84
|
resource_class = double
|
68
85
|
filtering = Filtering.new(filtering_resource,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jfelchner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: human_error
|