Class: JSONPatcher::ObjectPatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/jsonpatcher/object_patcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(callables) ⇒ ObjectPatcher

Returns a new instance of ObjectPatcher.



3
4
5
# File 'lib/jsonpatcher/object_patcher.rb', line 3

def initialize(callables)
  @patcher = callables
end

Instance Method Details

#call(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/jsonpatcher/object_patcher.rb', line 7

def call(hash)
  patched = {}
  hash.each do |k, v|
    patcher = @patcher[k.to_sym]
    if patcher
      patched[k] = patcher.call(v)
    else
      patched[k] = v
    end
  end
  patched
end