blank_empty_nil_filters 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +29 -2
- data/lib/blank_empty_nil_filters.rb +8 -0
- data/lib/blank_empty_nil_filters/version.rb +1 -1
- 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: 31f1a60dad0e7ba230e21358acf7a044d79852ac
|
4
|
+
data.tar.gz: 7ace2d848b525742ba194b7300e21ef1716a6366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99a10a6017b9dbbeafcff7acdd8ef9d15fca64dbc638dabbf479113017533fb3ca219351b47f2f38332deec2d16de6eea2f9b9ed822e5a86d8277925ad3c65fc
|
7
|
+
data.tar.gz: bf611e7b505e56e571e4bc78cd2ff61c48b49a23fe993db5773c5f46e5cb41bd16b9006f016f0d07daa6e6e6604afbb7057d02b6816935e0b00b2c799f71c0c1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -82,6 +82,18 @@ aoh.reject_values(:condition_method) # reject items matching :condition_method
|
|
82
82
|
aoh.select_values(:condition_method) # select items matching :condition_method
|
83
83
|
```
|
84
84
|
|
85
|
+
There are two `Object` instance methods of `no_empty_value` and `no_blank_value` that can be used as `String` or
|
86
|
+
other class instance filters to return the instance or a nil. This enables the use of `||` conditions to provide
|
87
|
+
alternative values:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
obj.no_empty_value || 'default'
|
91
|
+
obj.no_blank_value || 'default'
|
92
|
+
```
|
93
|
+
|
94
|
+
These two methods are like `ActiveSupport`'s `presence` method but with finer-grain control.
|
95
|
+
|
96
|
+
### Condition Methods
|
85
97
|
|
86
98
|
The methods below are used with the general purpose methods to form the special-case filters.
|
87
99
|
|
@@ -98,6 +110,7 @@ obj.non_nil? # !object.nil?
|
|
98
110
|
For _hash_ or _array_ objects, `is_empty?` and `is_blank?` work recursively on the object
|
99
111
|
elements, and the result is true only if true at every level.
|
100
112
|
|
113
|
+
### Hash key and value filters
|
101
114
|
There are also convenience methods to select the keys from filtered hash items:
|
102
115
|
|
103
116
|
```ruby
|
@@ -190,10 +203,24 @@ To filter out _blank_ values from an array:
|
|
190
203
|
[:1 " " " " nil ['' ' '] :2].no_blank_values => [:1 :2]
|
191
204
|
```
|
192
205
|
|
206
|
+
### String Filters
|
207
|
+
|
208
|
+
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.
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
' no fun '.no_empty_value || 'other' ==> ' no fun '
|
212
|
+
''. no_empty_value || 'other' ==> 'other'
|
213
|
+
' '. no_empty_value || 'other' ==> ' '
|
214
|
+
' answer '.no_blank_value || 'no' ==> ' answer '
|
215
|
+
' '. no_blank_value || 'no' ==> 'no'
|
216
|
+
'\n'. no_blank_value || 'no' ==> 'no'
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
|
193
221
|
## Testing
|
194
222
|
|
195
|
-
There is an `rspec`-style test in the `spec` directory, the perusal of which will also provide
|
196
|
-
some examples of usage.
|
223
|
+
There is an `rspec`-style test in the `spec` directory, the perusal of which will also provide some examples of usage.
|
197
224
|
|
198
225
|
The rspec-style tests are normally run under the `fuubar` formatter gem which shows an incremental summary on a single line. The
|
199
226
|
tests can be run with `rake` or with `rspec`:
|
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.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alan Stebbens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|