blank_empty_nil_filters 0.1.3 → 1.0.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 +4 -4
- data/Gemfile.lock +71 -75
- data/README.md +49 -23
- data/lib/blank_empty_nil_filters/version.rb +7 -1
- data/lib/blank_empty_nil_filters.rb +6 -2
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 050ecf453b9f1337450920915eff6d0c33f228e12a41df2ab00d3d7ab14f9904
|
|
4
|
+
data.tar.gz: 691b76327aa76b7e61a1e521df5b4807a3ec117171480a9b375c142e7d051c7d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 835e07d0ba6be825c8ea574427fbd0cd995e133bb8473345af404d0495ea44386274d2161b204bf1f6ef842c7312e0adc81692574f227cb58897c3599d30fc9b
|
|
7
|
+
data.tar.gz: 27e8e1c1c8fa33bc12b9aafac71179b69ef35e7b019e908ebca4b4eb4700b0da8cf1f4689229ca753c3b547f551136afd3ace1f1828287fad5fdd13d4f7e39d7
|
data/Gemfile.lock
CHANGED
|
@@ -1,35 +1,29 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
blank_empty_nil_filters (0.
|
|
4
|
+
blank_empty_nil_filters (1.0.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
concurrent-ruby (1.1.5)
|
|
19
|
-
diff-lcs (1.3)
|
|
20
|
-
docile (1.3.1)
|
|
21
|
-
ffi (1.10.0)
|
|
22
|
-
formatador (0.2.5)
|
|
23
|
-
fuubar (2.3.2)
|
|
9
|
+
ast (2.4.2)
|
|
10
|
+
builder (3.3.0)
|
|
11
|
+
byebug (11.1.3)
|
|
12
|
+
coderay (1.1.3)
|
|
13
|
+
diff-lcs (1.5.1)
|
|
14
|
+
docile (1.4.0)
|
|
15
|
+
ffi (1.17.0)
|
|
16
|
+
formatador (1.1.0)
|
|
17
|
+
fuubar (2.5.1)
|
|
24
18
|
rspec-core (~> 3.0)
|
|
25
19
|
ruby-progressbar (~> 1.4)
|
|
26
|
-
guard (2.
|
|
20
|
+
guard (2.18.1)
|
|
27
21
|
formatador (>= 0.2.4)
|
|
28
22
|
listen (>= 2.7, < 4.0)
|
|
29
23
|
lumberjack (>= 1.0.12, < 2.0)
|
|
30
24
|
nenv (~> 0.1)
|
|
31
25
|
notiffany (~> 0.0)
|
|
32
|
-
pry (>= 0.
|
|
26
|
+
pry (>= 0.13.0)
|
|
33
27
|
shellany (~> 0.0)
|
|
34
28
|
thor (>= 0.18.1)
|
|
35
29
|
guard-compat (1.2.1)
|
|
@@ -40,80 +34,82 @@ GEM
|
|
|
40
34
|
guard-yard (2.2.1)
|
|
41
35
|
guard (>= 1.1.0)
|
|
42
36
|
yard (>= 0.7.0)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
ruby_dep (~> 1.2)
|
|
51
|
-
lumberjack (1.0.13)
|
|
52
|
-
method_source (0.9.2)
|
|
53
|
-
minitest (5.11.3)
|
|
37
|
+
json (2.7.2)
|
|
38
|
+
language_server-protocol (3.17.0.3)
|
|
39
|
+
listen (3.9.0)
|
|
40
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
41
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
|
42
|
+
lumberjack (1.2.10)
|
|
43
|
+
method_source (1.1.0)
|
|
54
44
|
nenv (0.3.0)
|
|
55
|
-
notiffany (0.1.
|
|
45
|
+
notiffany (0.1.3)
|
|
56
46
|
nenv (~> 0.1)
|
|
57
47
|
shellany (~> 0.0)
|
|
58
|
-
parallel (1.
|
|
59
|
-
parser (
|
|
60
|
-
ast (~> 2.4.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
48
|
+
parallel (1.25.1)
|
|
49
|
+
parser (3.3.3.0)
|
|
50
|
+
ast (~> 2.4.1)
|
|
51
|
+
racc
|
|
52
|
+
pry (0.14.2)
|
|
53
|
+
coderay (~> 1.1)
|
|
54
|
+
method_source (~> 1.0)
|
|
55
|
+
pry-byebug (3.10.1)
|
|
65
56
|
byebug (~> 11.0)
|
|
66
|
-
pry (
|
|
67
|
-
|
|
68
|
-
rainbow (3.
|
|
69
|
-
rake (
|
|
70
|
-
rb-fsevent (0.
|
|
71
|
-
rb-inotify (0.
|
|
57
|
+
pry (>= 0.13, < 0.15)
|
|
58
|
+
racc (1.8.0)
|
|
59
|
+
rainbow (3.1.1)
|
|
60
|
+
rake (13.2.1)
|
|
61
|
+
rb-fsevent (0.11.2)
|
|
62
|
+
rb-inotify (0.11.1)
|
|
72
63
|
ffi (~> 1.0)
|
|
73
|
-
redcarpet (3.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
rspec-
|
|
80
|
-
|
|
64
|
+
redcarpet (3.6.0)
|
|
65
|
+
regexp_parser (2.9.2)
|
|
66
|
+
rexml (3.3.1)
|
|
67
|
+
strscan
|
|
68
|
+
rspec (3.13.0)
|
|
69
|
+
rspec-core (~> 3.13.0)
|
|
70
|
+
rspec-expectations (~> 3.13.0)
|
|
71
|
+
rspec-mocks (~> 3.13.0)
|
|
72
|
+
rspec-core (3.13.0)
|
|
73
|
+
rspec-support (~> 3.13.0)
|
|
74
|
+
rspec-expectations (3.13.1)
|
|
81
75
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
82
|
-
rspec-support (~> 3.
|
|
83
|
-
rspec-mocks (3.
|
|
76
|
+
rspec-support (~> 3.13.0)
|
|
77
|
+
rspec-mocks (3.13.1)
|
|
84
78
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
85
|
-
rspec-support (~> 3.
|
|
86
|
-
rspec-support (3.
|
|
79
|
+
rspec-support (~> 3.13.0)
|
|
80
|
+
rspec-support (3.13.1)
|
|
87
81
|
rspec_junit (4.0.4)
|
|
88
82
|
builder (>= 3.2.2)
|
|
89
83
|
rspec (>= 3.3.0)
|
|
90
|
-
rspec_junit_formatter (0.
|
|
84
|
+
rspec_junit_formatter (0.6.0)
|
|
91
85
|
rspec-core (>= 2, < 4, != 2.12.0)
|
|
92
|
-
rubocop (
|
|
93
|
-
|
|
86
|
+
rubocop (1.64.1)
|
|
87
|
+
json (~> 2.3)
|
|
88
|
+
language_server-protocol (>= 3.17.0)
|
|
94
89
|
parallel (~> 1.10)
|
|
95
|
-
parser (>=
|
|
96
|
-
psych (>= 3.1.0)
|
|
90
|
+
parser (>= 3.3.0.2)
|
|
97
91
|
rainbow (>= 2.2.2, < 4.0)
|
|
92
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
93
|
+
rexml (>= 3.2.5, < 4.0)
|
|
94
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
|
98
95
|
ruby-progressbar (~> 1.7)
|
|
99
|
-
unicode-display_width (>=
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
|
97
|
+
rubocop-ast (1.31.3)
|
|
98
|
+
parser (>= 3.3.1.0)
|
|
99
|
+
ruby-progressbar (1.13.0)
|
|
102
100
|
shellany (0.0.1)
|
|
103
|
-
simplecov (0.
|
|
101
|
+
simplecov (0.22.0)
|
|
104
102
|
docile (~> 1.1)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
simplecov-html (0.
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
simplecov-html (~> 0.11)
|
|
104
|
+
simplecov_json_formatter (~> 0.1)
|
|
105
|
+
simplecov-html (0.12.3)
|
|
106
|
+
simplecov_json_formatter (0.1.4)
|
|
107
|
+
spring (4.2.1)
|
|
108
|
+
strscan (3.1.0)
|
|
110
109
|
terminal-notifier-guard (1.7.0)
|
|
111
|
-
thor (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
thread_safe (~> 0.1)
|
|
115
|
-
unicode-display_width (1.5.0)
|
|
116
|
-
yard (0.9.19)
|
|
110
|
+
thor (1.3.1)
|
|
111
|
+
unicode-display_width (2.5.0)
|
|
112
|
+
yard (0.9.36)
|
|
117
113
|
|
|
118
114
|
PLATFORMS
|
|
119
115
|
ruby
|
data/README.md
CHANGED
|
@@ -6,10 +6,10 @@ Build status: [_,
|
|
12
|
-
empty _(zero length)_, or
|
|
12
|
+
empty _(zero length)_, or _nil_, and do so recursively.
|
|
13
13
|
|
|
14
14
|
The default behavior is to filter recursively, without limit.
|
|
15
15
|
However, optional arguments may be applied to any filter method to
|
|
@@ -20,7 +20,7 @@ level hashes can be completely removed if they are empty.
|
|
|
20
20
|
|
|
21
21
|
Note: `ActiveSupport` provides _some_ of these methods, but in general
|
|
22
22
|
is a *much* larger body of code. This module are only those methods
|
|
23
|
-
related to "blank", "empty" or nil
|
|
23
|
+
related to "blank", "empty" or `nil`. Also, `ActiveSupport` uses
|
|
24
24
|
`Regexp` `match` to determine blankness, while this code uses a
|
|
25
25
|
non-destructive `strip`, which is both faster and less sensitive to
|
|
26
26
|
non-UTF8 string error conditions.
|
|
@@ -87,9 +87,9 @@ aoh.reject_blank_values # aoh.no_blank_values
|
|
|
87
87
|
aoh.reject_nil_values # aoh.no_nil_values
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Any of the above methods can be provided optional arguments of _start_ and
|
|
91
|
-
to indicate levels at which filter _(selecting or rejecting)_ should
|
|
92
|
-
stop.
|
|
90
|
+
Any of the above methods can be provided optional arguments of _start_ and
|
|
91
|
+
_depth_ to indicate levels at which filter _(selecting or rejecting)_ should
|
|
92
|
+
start and stop.
|
|
93
93
|
|
|
94
94
|
```ruby
|
|
95
95
|
aoh.no_empty_values(1) # no empty items at level 1 or higher; leave level 0 alone
|
|
@@ -107,16 +107,27 @@ aoh.reject_values(:condition_method) # reject items matching :condition_method
|
|
|
107
107
|
aoh.select_values(:condition_method) # select items matching :condition_method
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
There are two `Object` instance methods of `no_empty_value` and `no_blank_value`
|
|
111
|
-
|
|
110
|
+
There are two `Object` instance methods of `no_empty_value` and `no_blank_value`
|
|
111
|
+
that can be used as `String` or other class instance filters to return the
|
|
112
|
+
instance or a nil. This enables the use of `||` conditions to provide
|
|
112
113
|
alternative values:
|
|
113
114
|
|
|
115
|
+
These methods all return the non-empty value, or a nil.
|
|
114
116
|
```ruby
|
|
115
117
|
obj.no_empty_value || 'default'
|
|
118
|
+
obj.non_empty || 'default'
|
|
119
|
+
obj.no_empty || 'default'
|
|
120
|
+
````
|
|
121
|
+
|
|
122
|
+
These methods all return the non-blank value, or a nil.
|
|
123
|
+
```ruby
|
|
116
124
|
obj.no_blank_value || 'default'
|
|
125
|
+
obj.non_blank || 'default'
|
|
126
|
+
obj.no_blank || 'default'
|
|
117
127
|
```
|
|
118
128
|
|
|
119
|
-
|
|
129
|
+
The `non_empty` are like `ActiveSupport`'s `presence` method but with
|
|
130
|
+
finer-grain control.
|
|
120
131
|
|
|
121
132
|
### Condition Methods
|
|
122
133
|
|
|
@@ -132,8 +143,8 @@ obj.non_blank? # true if object is not nil and has non-zero size, and is not
|
|
|
132
143
|
obj.non_nil? # !object.nil?
|
|
133
144
|
```
|
|
134
145
|
|
|
135
|
-
For _hash_ or _array_ objects, `is_empty?` and `is_blank?` work recursively on
|
|
136
|
-
elements, and the result is true only if true at every level.
|
|
146
|
+
For _hash_ or _array_ objects, `is_empty?` and `is_blank?` work recursively on
|
|
147
|
+
the object elements, and the result is true only if true at every level.
|
|
137
148
|
|
|
138
149
|
### Hash key and value filters
|
|
139
150
|
There are also convenience methods to select the keys from filtered hash items:
|
|
@@ -152,8 +163,9 @@ hash.non_blank_value_keys => hash.no_blank_values.keys
|
|
|
152
163
|
|
|
153
164
|
### Hash Filters
|
|
154
165
|
|
|
155
|
-
The most common usage of `no_empty_values` is with hashes of parameters, which
|
|
156
|
-
many variables, and then the empty or blank ones can be easily
|
|
166
|
+
The most common usage of `no_empty_values` is with hashes of parameters, which
|
|
167
|
+
are formed from many variables, and then the empty or blank ones can be easily
|
|
168
|
+
filtered out of the hash:
|
|
157
169
|
|
|
158
170
|
```ruby
|
|
159
171
|
{ 'Input' => {
|
|
@@ -168,6 +180,9 @@ many variables, and then the empty or blank ones can be easily filtered out of t
|
|
|
168
180
|
}.no_empty_values
|
|
169
181
|
```
|
|
170
182
|
|
|
183
|
+
Ruby's `Hash` `compact` instance method can remove key-value pairs with nil
|
|
184
|
+
values, but does not filter for blank or empty values, or recurse.
|
|
185
|
+
|
|
171
186
|
With `params` containing:
|
|
172
187
|
|
|
173
188
|
```ruby
|
|
@@ -197,9 +212,9 @@ params.no_blank_values => { type: :pdf }
|
|
|
197
212
|
|
|
198
213
|
#### Finding keys with empty values
|
|
199
214
|
|
|
200
|
-
Sometimes, it's not the key-value pairs that are non-empty that are desired;
|
|
201
|
-
the programmer often wants the keys with empty, blank, or nil values,
|
|
202
|
-
be reported on)_.
|
|
215
|
+
Sometimes, it's not the key-value pairs that are non-empty that are desired;
|
|
216
|
+
instead, the programmer often wants the keys with empty, blank, or nil values,
|
|
217
|
+
_(e.g., so they can be reported on)_.
|
|
203
218
|
|
|
204
219
|
```ruby
|
|
205
220
|
params = { file: ' ', type: :pdf, pattern: nil, dest: ''}
|
|
@@ -218,7 +233,9 @@ To filter out empty (zero-length) values from an array:
|
|
|
218
233
|
[:1 ['' :b] nil :2 ['' '']].no_empty_values => [:1 [:b] :2]
|
|
219
234
|
```
|
|
220
235
|
|
|
221
|
-
Note that the filter is recursive, and if a sub-array is entirely empty, it is
|
|
236
|
+
Note that the filter is recursive, and if a sub-array is entirely empty, it is
|
|
237
|
+
filtered out also _(because it also has zero length, after its items have been
|
|
238
|
+
filtered)_.
|
|
222
239
|
|
|
223
240
|
The `nil` is considered an "empty" value.
|
|
224
241
|
|
|
@@ -230,7 +247,9 @@ To filter out _blank_ values from an array:
|
|
|
230
247
|
|
|
231
248
|
### String Filters
|
|
232
249
|
|
|
233
|
-
The `no_empty_value` and `no_blank_value` methods on the `Object` class can be
|
|
250
|
+
The `no_empty_value` and `no_blank_value` methods on the `Object` class can be
|
|
251
|
+
applied to any object that supports the `is_blank?` and `is_empty?` condition
|
|
252
|
+
methods, including the `String` class.
|
|
234
253
|
|
|
235
254
|
```ruby
|
|
236
255
|
' no fun '.no_empty_value || 'other' ==> ' no fun '
|
|
@@ -245,10 +264,12 @@ The `no_empty_value` and `no_blank_value` methods on the `Object` class can be a
|
|
|
245
264
|
|
|
246
265
|
## Testing
|
|
247
266
|
|
|
248
|
-
There is an `rspec`-style test in the `spec` directory, the perusal of which
|
|
267
|
+
There is an `rspec`-style test in the `spec` directory, the perusal of which
|
|
268
|
+
will also provide some examples of usage.
|
|
249
269
|
|
|
250
|
-
The rspec-style tests are normally run under the `fuubar` formatter gem which
|
|
251
|
-
tests can be run with `rake`
|
|
270
|
+
The rspec-style tests are normally run under the `fuubar` formatter gem which
|
|
271
|
+
shows an incremental summary on a single line. The tests can be run with `rake`
|
|
272
|
+
or with `rspec`:
|
|
252
273
|
|
|
253
274
|
bundle exec rake spec
|
|
254
275
|
|
|
@@ -256,7 +277,8 @@ or
|
|
|
256
277
|
|
|
257
278
|
bundle exec rspec
|
|
258
279
|
|
|
259
|
-
However, if you wish to see all of the usual "documentation" style output, use
|
|
280
|
+
However, if you wish to see all of the usual "documentation" style output, use
|
|
281
|
+
the `-f doc` option on the `rspec` invocation:
|
|
260
282
|
|
|
261
283
|
bundle exec rspec -f doc
|
|
262
284
|
|
|
@@ -264,7 +286,11 @@ However, if you wish to see all of the usual "documentation" style output, use t
|
|
|
264
286
|
|
|
265
287
|
After checking out the repo, run `rake spec` to run the tests.
|
|
266
288
|
|
|
267
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
289
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
290
|
+
release a new version, update the version number in `version.rb`, and then
|
|
291
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
|
292
|
+
push git commits and tags, and push the `.gem` file
|
|
293
|
+
to [rubygems.org](https://rubygems.org).
|
|
268
294
|
|
|
269
295
|
|
|
270
296
|
## Contributing
|
|
@@ -37,6 +37,7 @@ module BlankEmptyNilFilters
|
|
|
37
37
|
end
|
|
38
38
|
alias reject_blank_values no_blank_values
|
|
39
39
|
|
|
40
|
+
# more capable than just ARRAY.compact
|
|
40
41
|
def no_nil_values(start = 0, depth = nil, level = 0)
|
|
41
42
|
reject_values(:nil?, start, depth, level)
|
|
42
43
|
end
|
|
@@ -119,6 +120,7 @@ module BlankEmptyNilFilters
|
|
|
119
120
|
end
|
|
120
121
|
alias select_blank_values only_blank_values
|
|
121
122
|
|
|
123
|
+
# more capable than just HASH.compact
|
|
122
124
|
def no_nil_values(start = 0, depth = nil, level = 0)
|
|
123
125
|
reject_values(:nil?, start, depth, level)
|
|
124
126
|
end
|
|
@@ -205,13 +207,15 @@ module BlankEmptyNilFilters
|
|
|
205
207
|
end
|
|
206
208
|
|
|
207
209
|
module ObjectExtensions
|
|
208
|
-
def
|
|
210
|
+
def non_blank
|
|
209
211
|
is_blank? ? nil : self
|
|
210
212
|
end
|
|
213
|
+
alias no_blank_value non_blank
|
|
211
214
|
|
|
212
|
-
def
|
|
215
|
+
def non_empty
|
|
213
216
|
is_empty? ? nil : self
|
|
214
217
|
end
|
|
218
|
+
alias no_empty_value non_empty
|
|
215
219
|
|
|
216
220
|
def is_empty?
|
|
217
221
|
if nil?
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: blank_empty_nil_filters
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alan Stebbens
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-01-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -259,7 +259,7 @@ homepage: https://github.com/aks/blank_empty_nil_filters
|
|
|
259
259
|
licenses:
|
|
260
260
|
- MIT
|
|
261
261
|
metadata: {}
|
|
262
|
-
post_install_message:
|
|
262
|
+
post_install_message:
|
|
263
263
|
rdoc_options: []
|
|
264
264
|
require_paths:
|
|
265
265
|
- lib
|
|
@@ -274,8 +274,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
274
274
|
- !ruby/object:Gem::Version
|
|
275
275
|
version: '0'
|
|
276
276
|
requirements: []
|
|
277
|
-
rubygems_version: 3.
|
|
278
|
-
signing_key:
|
|
277
|
+
rubygems_version: 3.4.19
|
|
278
|
+
signing_key:
|
|
279
279
|
specification_version: 4
|
|
280
280
|
summary: '["Extensions for filtering empty, blank, and nil values from Hashes and
|
|
281
281
|
Arrays", "Extentions for convenient filtering of blank, empty, and nil values from\nHash
|