hash_miner 1.1.0 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash_miner/hash.rb +11 -7
- data/lib/hash_miner/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: 95fbf6c5c47f533153bccfd32b192fbf83fce8fc4771933261362f669539b17f
|
4
|
+
data.tar.gz: 3809d629d23c19374e919f16809603f882858b9c4a46d6fc3da0fdd3d337717f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f457d4f4c48a11bc095fc1b90d4603f21a9358abbe6f69212c8ca9a55d4ea5c6d98df182b37269dc82d2c341ac6bb6f2cdc9af4d701e92662c0bb4f02aa46f46
|
7
|
+
data.tar.gz: d8bb9284e3faab4fce3af97c7c95b11290c0a330b2e51e3c07811eaff73b804412cdff42f46964b862c8d5d745b4b14c423d941fb11d1b710f845ffdbab37a36
|
data/lib/hash_miner/hash.rb
CHANGED
@@ -11,7 +11,7 @@ class Hash
|
|
11
11
|
#
|
12
12
|
# @return [Boolean] whether the key was found
|
13
13
|
def deep_contains?(key:, hash: self)
|
14
|
-
return
|
14
|
+
return false unless hash.is_a? Hash
|
15
15
|
return true if hash.include? key
|
16
16
|
|
17
17
|
hash.filter_map do |_k, v|
|
@@ -245,37 +245,41 @@ class Hash
|
|
245
245
|
end
|
246
246
|
|
247
247
|
def deep_find_logic(hash:, key:)
|
248
|
-
hash.
|
248
|
+
results = hash.map do |k, v|
|
249
249
|
if k.eql? key
|
250
250
|
v
|
251
251
|
elsif v.is_a?(Hash)
|
252
252
|
deep_find_logic(hash: v, key: key)
|
253
253
|
elsif v.is_a?(Array)
|
254
|
-
[v.
|
255
|
-
deep_find_logic(hash:
|
254
|
+
[v.map do |item|
|
255
|
+
deep_find_logic(hash: item, key: key) if item.is_a?(Hash) && item.deep_contains?(key: key)
|
256
256
|
end]
|
257
257
|
end
|
258
258
|
end.flatten
|
259
|
+
|
260
|
+
results.all?(nil) ? results.uniq : results.compact
|
259
261
|
end
|
260
262
|
|
261
263
|
def deep_find_parent_logic(hash:, key:, parent:)
|
262
|
-
hash.
|
264
|
+
results = hash.map do |k, v|
|
263
265
|
if (parent.is_a?(Array) && parent.include?(k)) || parent.eql?(k)
|
264
266
|
case v
|
265
267
|
when Hash
|
266
268
|
deep_find_logic(key: key, hash: v)
|
267
269
|
when Array
|
268
|
-
[v.
|
270
|
+
[v.map do |item|
|
269
271
|
deep_find_logic(key: key, hash: item) if item.is_a?(Hash) && item.deep_contains?(key: key)
|
270
272
|
end]
|
271
273
|
end
|
272
274
|
elsif v.is_a?(Hash) && v.deep_contains?(key: key)
|
273
275
|
deep_find_parent_logic(hash: v, key: key, parent: parent)
|
274
276
|
elsif v.is_a?(Array)
|
275
|
-
[v.
|
277
|
+
[v.map do |item|
|
276
278
|
deep_find_parent_logic(hash: item, key: key, parent: parent) if item.is_a?(Hash) && item.deep_contains?(key: key)
|
277
279
|
end]
|
278
280
|
end
|
279
281
|
end.flatten
|
282
|
+
|
283
|
+
results.all?(nil) ? results.uniq : results.compact
|
280
284
|
end
|
281
285
|
end
|
data/lib/hash_miner/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_miner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alexo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Additional Hash methods to help navigate the tricky world of nested Hashes.
|
14
14
|
email:
|