Class: Amplitude::HashSlicer

Inherits:
Object
  • Object
show all
Defined in:
lib/amplitude/hash_slicer.rb

Class Method Summary collapse

Class Method Details

.call(obj, *keys) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/amplitude/hash_slicer.rb', line 3

def call(obj, *keys)
  return {} if keys.length == 0

  keys = keys[0] if keys[0].is_a?(Array)
  hash = obj.to_h

  if hash.respond_to?(:slice)
    slice_hash(hash, keys)
  else
    map_hash(hash, keys)
  end
end