hash_miner 1.1.1 → 1.1.3
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 +10 -6
- data/lib/hash_miner/version.rb +1 -1
- data/lib/hash_miner.rb +0 -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: 4c28ed8e77715801a99cd92d331d7549429fdbfd77d3218bd98486d834c56f5b
|
4
|
+
data.tar.gz: 7ee17212ebc13fcf04dde9af61570ef9cc76320d4391df466a891b4a3217f29f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 658eba36f1d5ec2ba46159bfd7ad527b919dc66f24df86072ce29988c938a09d9a4fbb4988a0e8a45ab27cc061e497ddcae26293aa75d8f8bc8c187baedf43c0
|
7
|
+
data.tar.gz: 666591c8e3a537cd5bc9eb1f829660df4d6879666c66c6024aa10ada7375050ac7cd03ede9d03485fb9de682665340d7f4f533f724b5290b15cbc980dfd76ff4
|
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.
|
254
|
+
[v.map do |item|
|
255
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
data/lib/hash_miner.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.3
|
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-16 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:
|