everythingrb 0.2.4 → 0.2.5
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/CHANGELOG.md +16 -2
- data/README.md +45 -0
- data/lib/everythingrb/core/array.rb +81 -0
- data/lib/everythingrb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 330f80c66964fd22cd85850c251963ea372957a2b3190f4abcb5d0f3346989f7
|
4
|
+
data.tar.gz: f28ebe4ab45e0bb7f1e68f2553af302d6ab2dfaa0509bc3d73615a84330b6d1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae50b585bb625724ca3e7ae917074fef6ceb25278818c88965aa10ccfae42e067b2716fc36b2f4da0d2cd4b4228b764166c12a43c212c7b44b3874ebe00aa071
|
7
|
+
data.tar.gz: 5558f7dfe032d20489d7accf298eb889ffb22cd4a215509e4d2fd90fa35c23eebefa95ca2170695d4b82a637eb2583daa5a3b11b1660b9a9ccb1fa3b9dc5dcf9
|
data/CHANGELOG.md
CHANGED
@@ -23,6 +23,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
23
23
|
|
24
24
|
### Removed
|
25
25
|
|
26
|
+
## [0.2.5] - 12025-03-29
|
27
|
+
|
28
|
+
### Added
|
29
|
+
|
30
|
+
- New array trimming methods that preserve internal structure:
|
31
|
+
- `compact_prefix` - Removes nil values from the beginning of an array
|
32
|
+
- `compact_suffix` - Removes nil values from the end of an array
|
33
|
+
- `trim_nils` - Removes nil values from both ends of an array
|
34
|
+
- ActiveSupport integration with blank-aware versions:
|
35
|
+
- `compact_blank_prefix` - Removes blank values from the beginning
|
36
|
+
- `compact_blank_suffix` - Removes blank values from the end
|
37
|
+
- `trim_blanks` - Removes blank values from both ends
|
38
|
+
|
26
39
|
## [0.2.4] - 12025-03-20
|
27
40
|
|
28
41
|
### Changed
|
@@ -111,8 +124,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
111
124
|
|
112
125
|
- Added alias `each` to `each_pair` in OpenStruct for better enumerable compatibility
|
113
126
|
|
114
|
-
[unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.2.
|
115
|
-
[0.2.
|
127
|
+
[unreleased]: https://github.com/itsthedevman/everythingrb/compare/v0.2.5...HEAD
|
128
|
+
[0.2.5]: https://github.com/itsthedevman/everythingrb/compare/v0.2.4...v0.2.5
|
129
|
+
[0.2.4]: https://github.com/itsthedevman/everythingrb/compare/v0.2.3...v0.2.4
|
116
130
|
[0.2.3]: https://github.com/itsthedevman/everythingrb/compare/v0.2.2...v0.2.3
|
117
131
|
[0.2.2]: https://github.com/itsthedevman/everythingrb/compare/v0.2.1...v0.2.2
|
118
132
|
[0.2.1]: https://github.com/itsthedevman/everythingrb/compare/v0.2.0...v0.2.1
|
data/README.md
CHANGED
@@ -22,6 +22,7 @@ I'm currently looking for opportunities where I can tackle meaningful problems a
|
|
22
22
|
- [Collection Processing](#collection-processing)
|
23
23
|
- [JSON & String Handling](#json--string-handling)
|
24
24
|
- [Object Freezing](#object-freezing)
|
25
|
+
- [Array Trimming](#array-trimming)
|
25
26
|
- [Predicate Methods](#predicate-methods)
|
26
27
|
- [Core Extensions](#core-extensions)
|
27
28
|
- [Array](#array)
|
@@ -138,6 +139,22 @@ config[:api][:endpoints].frozen? # => true
|
|
138
139
|
config[:api][:endpoints][0].frozen? # => true
|
139
140
|
```
|
140
141
|
|
142
|
+
### Array Trimming
|
143
|
+
|
144
|
+
Clean up array boundaries without losing internal structure:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
# Remove nil values from the beginning or end
|
148
|
+
[nil, nil, 1, nil, 2, nil, nil].trim_nils # => [1, nil, 2]
|
149
|
+
|
150
|
+
# With ActiveSupport, remove any blank values (nil, "", etc.)
|
151
|
+
[nil, "", 1, "", 2, nil, ""].trim_blanks # => [1, "", 2]
|
152
|
+
|
153
|
+
# Only trim from one end if needed
|
154
|
+
[nil, nil, 1, 2, 3].compact_prefix # => [1, 2, 3]
|
155
|
+
[1, 2, 3, nil, nil].compact_suffix # => [1, 2, 3]
|
156
|
+
```
|
157
|
+
|
141
158
|
### Predicate Methods
|
142
159
|
|
143
160
|
Create boolean accessors with minimal code:
|
@@ -228,6 +245,34 @@ data.dig_map(:user, :profile, :name)
|
|
228
245
|
# => ["Alice", "Bob"]
|
229
246
|
```
|
230
247
|
|
248
|
+
#### `compact_prefix` / `compact_suffix` / `trim_nils`
|
249
|
+
Remove nil values from the beginning, end, or both ends of an array without touching interior nil values.
|
250
|
+
|
251
|
+
```ruby
|
252
|
+
[nil, nil, 1, nil, 2, nil, nil].compact_prefix
|
253
|
+
# => [1, nil, 2, nil, nil]
|
254
|
+
|
255
|
+
[1, nil, 2, nil, nil].compact_suffix
|
256
|
+
# => [1, nil, 2]
|
257
|
+
|
258
|
+
[nil, nil, 1, nil, 2, nil, nil].trim_nils
|
259
|
+
# => [1, nil, 2]
|
260
|
+
```
|
261
|
+
|
262
|
+
#### `compact_blank_prefix` / `compact_blank_suffix` / `trim_blanks` (with ActiveSupport)
|
263
|
+
Remove blank values (nil, empty strings, etc.) from the beginning, end, or both ends of an array.
|
264
|
+
|
265
|
+
```ruby
|
266
|
+
[nil, "", 1, "", 2, nil, ""].compact_blank_prefix
|
267
|
+
# => [1, "", 2, nil, ""]
|
268
|
+
|
269
|
+
[nil, "", 1, "", 2, nil, ""].compact_blank_suffix
|
270
|
+
# => [nil, "", 1, "", 2]
|
271
|
+
|
272
|
+
[nil, "", 1, "", 2, nil, ""].trim_blanks
|
273
|
+
# => [1, "", 2]
|
274
|
+
```
|
275
|
+
|
231
276
|
#### `deep_freeze`
|
232
277
|
Recursively freezes an array and all of its nested elements.
|
233
278
|
|
@@ -97,4 +97,85 @@ class Array
|
|
97
97
|
each { |v| v.respond_to?(:deep_freeze) ? v.deep_freeze : v.freeze }
|
98
98
|
freeze
|
99
99
|
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Removes nil values from the beginning of an array
|
103
|
+
#
|
104
|
+
# @return [Array] Array with leading nil values removed
|
105
|
+
#
|
106
|
+
# @example
|
107
|
+
# [nil, nil, 1, 2, nil, 3].compact_prefix
|
108
|
+
# # => [1, 2, nil, 3]
|
109
|
+
#
|
110
|
+
def compact_prefix
|
111
|
+
drop_while(&:nil?)
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Removes nil values from the end of an array
|
116
|
+
#
|
117
|
+
# @return [Array] Array with trailing nil values removed
|
118
|
+
#
|
119
|
+
# @example
|
120
|
+
# [1, 2, nil, 3, nil, nil].compact_suffix
|
121
|
+
# # => [1, 2, nil, 3]
|
122
|
+
#
|
123
|
+
def compact_suffix
|
124
|
+
reverse.drop_while(&:nil?).reverse
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Removes nil values from both the beginning and end of an array
|
129
|
+
#
|
130
|
+
# @return [Array] Array with leading and trailing nil values removed
|
131
|
+
#
|
132
|
+
# @example
|
133
|
+
# [nil, nil, 1, 2, nil, 3, nil, nil].trim_nils
|
134
|
+
# # => [1, 2, nil, 3]
|
135
|
+
#
|
136
|
+
def trim_nils
|
137
|
+
compact_prefix.compact_suffix
|
138
|
+
end
|
139
|
+
|
140
|
+
# ActiveSupport integrations
|
141
|
+
if defined?(ActiveSupport)
|
142
|
+
#
|
143
|
+
# Removes blank values from the beginning of an array
|
144
|
+
#
|
145
|
+
# @return [Array] Array with leading blank values removed
|
146
|
+
#
|
147
|
+
# @example With ActiveSupport loaded
|
148
|
+
# [nil, "", 1, 2, "", 3].compact_blank_prefix
|
149
|
+
# # => [1, 2, "", 3]
|
150
|
+
#
|
151
|
+
def compact_blank_prefix
|
152
|
+
drop_while(&:blank?)
|
153
|
+
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# Removes blank values from the end of an array
|
157
|
+
#
|
158
|
+
# @return [Array] Array with trailing blank values removed
|
159
|
+
#
|
160
|
+
# @example With ActiveSupport loaded
|
161
|
+
# [1, 2, "", 3, nil, ""].compact_blank_suffix
|
162
|
+
# # => [1, 2, "", 3]
|
163
|
+
#
|
164
|
+
def compact_blank_suffix
|
165
|
+
reverse.drop_while(&:blank?).reverse
|
166
|
+
end
|
167
|
+
|
168
|
+
#
|
169
|
+
# Removes blank values from both the beginning and end of an array
|
170
|
+
#
|
171
|
+
# @return [Array] Array with leading and trailing blank values removed
|
172
|
+
#
|
173
|
+
# @example With ActiveSupport loaded
|
174
|
+
# [nil, "", 1, 2, "", 3, nil, ""].trim_blanks
|
175
|
+
# # => [1, 2, "", 3]
|
176
|
+
#
|
177
|
+
def trim_blanks
|
178
|
+
compact_blank_prefix.compact_blank_suffix
|
179
|
+
end
|
180
|
+
end
|
100
181
|
end
|
data/lib/everythingrb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: everythingrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ostruct
|