Module: DataProcessor::Manipulate

Included in:
DataProcessor
Defined in:
lib/data_processor/manipulate.rb

Instance Method Summary collapse

Instance Method Details

#manipulate(path, override = false) ⇒ Object



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

def manipulate(path, override=false)
  obj, parent_obj = traverse_path(@data, path)

  # execute block with object and parent object as params
  # ie. if the object is found
  # + override object with return value of block if needed
  if block_given? && obj
    block_return_value = yield(obj, parent_obj)
    parent_obj[path.split("/").last] = block_return_value if override
  end
end