hash_miner 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3880db2912ffc04192e8229d82182242e328393ef861aefca6afa13e18a6bf69
4
- data.tar.gz: c986c1425ec37db4c490ea0bb067c48021ba005592cc6fd3ee268b1eb08a9fbb
3
+ metadata.gz: 95fbf6c5c47f533153bccfd32b192fbf83fce8fc4771933261362f669539b17f
4
+ data.tar.gz: 3809d629d23c19374e919f16809603f882858b9c4a46d6fc3da0fdd3d337717f
5
5
  SHA512:
6
- metadata.gz: a4d6a1e3238607814b75ace25a4944945fa4efde24f4db3e816e7393d4416e4f77f637b3e784e9285e16e75c773d305fe9bbd5ab527979073256d6ad194cc54c
7
- data.tar.gz: 3acbbff3da20f5817b9e0ce4883753a89bbb6b27e2f7e464b43fbaa214b76a14bf7b544712196331233ec020b136166335f2e57e3bc6834d2b10c0beae39c1b0
6
+ metadata.gz: f457d4f4c48a11bc095fc1b90d4603f21a9358abbe6f69212c8ca9a55d4ea5c6d98df182b37269dc82d2c341ac6bb6f2cdc9af4d701e92662c0bb4f02aa46f46
7
+ data.tar.gz: d8bb9284e3faab4fce3af97c7c95b11290c0a330b2e51e3c07811eaff73b804412cdff42f46964b862c8d5d745b4b14c423d941fb11d1b710f845ffdbab37a36
@@ -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 nil unless hash.is_a? Hash
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.filter_map do |k, v|
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.filter_map do |item|
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.filter_map do |k, v|
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.filter_map do |item|
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.filter_map do |item|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HashMiner
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.2'
5
5
  end
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.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: 2022-07-18 00:00:00.000000000 Z
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: