apill 3.0.7 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da05f2e1ef3a9954f1db5c883a3706b4400a464c
4
- data.tar.gz: 9366bdce7f929450b390e6a244f4909af2a0cbb6
3
+ metadata.gz: 8bb09a75851259a89a82d3d9aff3a5aa05a7f72a
4
+ data.tar.gz: db6adc23f9d21ce30143c5aa7083af136aed499e
5
5
  SHA512:
6
- metadata.gz: d1b2c36378f440702c304e43971759c2d9833a896070763eceb95e1c1a0f3c47d9350833e63303d6e53186dacc512ef03435130f72b7b069abdf88c2bc29bc4f
7
- data.tar.gz: 1ca7869d85e96bcf410becae3c93b018eac7a2cf46d6ada8a5c84045053acef9d3514953a33da6dcd5e7781498965642d1b51c6d3eb8573721dbe2039519396a
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
@@ -1,3 +1,3 @@
1
1
  module Apill
2
- VERSION = '3.0.7'
2
+ VERSION = '3.1.0'
3
3
  end
@@ -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.7
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-13 00:00:00.000000000 Z
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: human_error