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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35a7e5e27066b542dc53c963f9f3769ea1a9da4667c69e5edad010158fe5717d
4
- data.tar.gz: dad47bacd3d2f9adfc63d42ca24dcea0ede3bb87e97ffb18bd25a3d15c39720b
3
+ metadata.gz: 050ecf453b9f1337450920915eff6d0c33f228e12a41df2ab00d3d7ab14f9904
4
+ data.tar.gz: 691b76327aa76b7e61a1e521df5b4807a3ec117171480a9b375c142e7d051c7d
5
5
  SHA512:
6
- metadata.gz: 141dae5987cfd3487d8c98977c1048036793ff8d2e2c49735ea630481aa23b5c6ee273325850f4351be126f11340f7045a1480606c264ecf2d57d0680781ed16
7
- data.tar.gz: 102f2f9132840745ee8ac2ca5e40a2bfd9b2e460acb32e090cb876ae63434aa4eba2e668f1cfb2500b34dcb69818435b242d267e09cb0d9572e48558f8824a04
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.1.3)
4
+ blank_empty_nil_filters (1.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activesupport (5.2.3)
10
- concurrent-ruby (~> 1.0, >= 1.0.2)
11
- i18n (>= 0.7, < 2)
12
- minitest (~> 5.1)
13
- tzinfo (~> 1.1)
14
- ast (2.4.0)
15
- builder (3.2.3)
16
- byebug (11.0.1)
17
- coderay (1.1.2)
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.15.0)
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.9.12)
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
- i18n (1.6.0)
44
- concurrent-ruby (~> 1.0)
45
- jaro_winkler (1.5.2)
46
- json (2.2.0)
47
- listen (3.1.5)
48
- rb-fsevent (~> 0.9, >= 0.9.4)
49
- rb-inotify (~> 0.9, >= 0.9.7)
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.1)
45
+ notiffany (0.1.3)
56
46
  nenv (~> 0.1)
57
47
  shellany (~> 0.0)
58
- parallel (1.17.0)
59
- parser (2.6.2.1)
60
- ast (~> 2.4.0)
61
- pry (0.12.2)
62
- coderay (~> 1.1.0)
63
- method_source (~> 0.9.0)
64
- pry-byebug (3.7.0)
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 (~> 0.10)
67
- psych (3.1.0)
68
- rainbow (3.0.0)
69
- rake (12.3.2)
70
- rb-fsevent (0.10.3)
71
- rb-inotify (0.10.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.4.0)
74
- rspec (3.8.0)
75
- rspec-core (~> 3.8.0)
76
- rspec-expectations (~> 3.8.0)
77
- rspec-mocks (~> 3.8.0)
78
- rspec-core (3.8.0)
79
- rspec-support (~> 3.8.0)
80
- rspec-expectations (3.8.2)
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.8.0)
83
- rspec-mocks (3.8.0)
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.8.0)
86
- rspec-support (3.8.0)
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.4.1)
84
+ rspec_junit_formatter (0.6.0)
91
85
  rspec-core (>= 2, < 4, != 2.12.0)
92
- rubocop (0.67.2)
93
- jaro_winkler (~> 1.5.1)
86
+ rubocop (1.64.1)
87
+ json (~> 2.3)
88
+ language_server-protocol (>= 3.17.0)
94
89
  parallel (~> 1.10)
95
- parser (>= 2.5, != 2.5.1.1)
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 (>= 1.4.0, < 1.6)
100
- ruby-progressbar (1.10.0)
101
- ruby_dep (1.5.0)
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.16.1)
101
+ simplecov (0.22.0)
104
102
  docile (~> 1.1)
105
- json (>= 1.8, < 3)
106
- simplecov-html (~> 0.10.0)
107
- simplecov-html (0.10.2)
108
- spring (2.0.2)
109
- activesupport (>= 4.2)
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 (0.20.3)
112
- thread_safe (0.3.6)
113
- tzinfo (1.2.5)
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: [![CircleCI](https://circleci.com/gh/aks/blank_empty_nil_filters/t
6
6
 
7
7
  This module creates new methods to be prepended to the Array, Hash,
8
8
  String, and Object classes to implement recursive filters for _blank_,
9
- _empty_, and nil values.
9
+ _empty_, and _nil_ values.
10
10
 
11
11
  The methods can select or reject values which are blank _(whitespace)_,
12
- empty _(zero length)_, or nil, and do so recursively.
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. Also, `ActiveSupport` uses
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 _depth_
91
- to indicate levels at which filter _(selecting or rejecting)_ should start and
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` that can be used as `String` or
111
- other class instance filters to return the instance or a nil. This enables the use of `||` conditions to provide
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
- These two methods are like `ActiveSupport`'s `presence` method but with finer-grain control.
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 the object
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 are formed from
156
- many variables, and then the empty or blank ones can be easily filtered out of the hash:
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; instead,
201
- the programmer often wants the keys with empty, blank, or nil values, _(e.g., so they can
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 filtered out also _(because it also has zero length, after its items have been filtered)_.
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 applied to any object that supports the `is_blank?` and `is_empty?` condition methods, including the `String` class.
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 will also provide some examples of usage.
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 shows an incremental summary on a single line. The
251
- tests can be run with `rake` or with `rspec`:
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 the `-f doc` option on the `rspec` invocation:
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 release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
@@ -1,5 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BlankEmptyNilFilters
4
- VERSION = '0.1.3'
4
+ RELEASES = [
5
+ ['1.0.0', '2025-01-21'],
6
+ ['0.2.0', '2020-08-28'],
7
+ ['0.1.1', '2019-05-23']
8
+ ].freeze
9
+
10
+ VERSION = RELEASES[0][0]
5
11
  end
@@ -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 no_blank_value
210
+ def non_blank
209
211
  is_blank? ? nil : self
210
212
  end
213
+ alias no_blank_value non_blank
211
214
 
212
- def no_empty_value
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.1.3
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: 2020-08-28 00:00:00.000000000 Z
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.1.2
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