module Trailblazer::Finder::Utils::Hash

Public Instance Methods

deep_locate(comparator, object, result = []) click to toggle source
# File lib/trailblazer/finder/utils/hash.rb, line 10
def deep_locate(comparator, object, result = [])
  if object.is_a?(::Enumerable) && comparator.is_a?(::Proc)
    result.push object if object.any? { |value| match_comparator?(value, comparator, object) }
    (object.respond_to?(:values) ? object.values : object.entries).each do |value|
      deep_locate(comparator, value, result)
    end
  end

  result
end
match_comparator?(value, comparator, object) click to toggle source
# File lib/trailblazer/finder/utils/hash.rb, line 21
def match_comparator?(value, comparator, object)
  key = nil
  key, value = value if object.is_a?(::Hash)
  comparator.call(key, value, object)
end
remove_keys_from_hash(hash, keys) click to toggle source
# File lib/trailblazer/finder/utils/hash.rb, line 27
def remove_keys_from_hash(hash, keys)
  hash.each do |key, _value|
    hash.delete(key) if keys.include?(key)
  end
  hash
end