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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 914562162950918230de98d58303185f43568f78dfca068bc2f7209f4f96ae2b
4
- data.tar.gz: 80e88d5b6d61b41e7aafb12fddf796c9eba40667895fc0cb8e62610e0160e04b
3
+ metadata.gz: 95fbf6c5c47f533153bccfd32b192fbf83fce8fc4771933261362f669539b17f
4
+ data.tar.gz: 3809d629d23c19374e919f16809603f882858b9c4a46d6fc3da0fdd3d337717f
5
5
  SHA512:
6
- metadata.gz: 52d4ae8b09bc42cccb5b3fd98180a100074292a98d4b0a0437d62f776e436b69b93c487f15524323995452c1a96b9a214e071bb9735dddfcfff0da251c6b2ed1
7
- data.tar.gz: c5af637056ca8c4950846fc497ecac8f34270425f176a2850da0002cebeddbc09c71ed601d381f4e5feb5012bfad84d27db116ce8ab11a3b9413da4e335291f9
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|
255
- deep_find_logic(hash: i, key: key) if item.is_a?(Hash) && item.deep_contains?(key: key)
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.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.0'
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.0
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-15 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: