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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3880db2912ffc04192e8229d82182242e328393ef861aefca6afa13e18a6bf69
4
- data.tar.gz: c986c1425ec37db4c490ea0bb067c48021ba005592cc6fd3ee268b1eb08a9fbb
3
+ metadata.gz: 4c28ed8e77715801a99cd92d331d7549429fdbfd77d3218bd98486d834c56f5b
4
+ data.tar.gz: 7ee17212ebc13fcf04dde9af61570ef9cc76320d4391df466a891b4a3217f29f
5
5
  SHA512:
6
- metadata.gz: a4d6a1e3238607814b75ace25a4944945fa4efde24f4db3e816e7393d4416e4f77f637b3e784e9285e16e75c773d305fe9bbd5ab527979073256d6ad194cc54c
7
- data.tar.gz: 3acbbff3da20f5817b9e0ce4883753a89bbb6b27e2f7e464b43fbaa214b76a14bf7b544712196331233ec020b136166335f2e57e3bc6834d2b10c0beae39c1b0
6
+ metadata.gz: 658eba36f1d5ec2ba46159bfd7ad527b919dc66f24df86072ce29988c938a09d9a4fbb4988a0e8a45ab27cc061e497ddcae26293aa75d8f8bc8c187baedf43c0
7
+ data.tar.gz: 666591c8e3a537cd5bc9eb1f829660df4d6879666c66c6024aa10ada7375050ac7cd03ede9d03485fb9de682665340d7f4f533f724b5290b15cbc980dfd76ff4
@@ -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.3'
5
5
  end
data/lib/hash_miner.rb CHANGED
@@ -4,7 +4,6 @@ require_relative 'hash_miner/version'
4
4
  require_relative 'hash_miner/hash'
5
5
  require_relative 'hash_miner/errors'
6
6
 
7
- require 'pry'
8
7
  require 'logger'
9
8
 
10
9
  # HashMiner gem
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.3
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-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: