Sha256: 0223e671735cf9969667108c27d30572f0b08d33e70cde60f9e656cafd1cf0a0

Contents?: true

Size: 581 Bytes

Versions: 2

Compression:

Stored size: 581 Bytes

Contents

class DataProcessor
  module Helpers

    def traverse_path(object, path, use_symbols=false)
      obj = object
      parent_obj = nil
      path_split = path.split("/")
      counter = 0

      # down the rabbit hole
      path_split.each do |p|
        p = p.to_sym if use_symbols

        if obj && obj[p]
          parent_obj = obj
          obj = obj[p]
          counter = counter + 1
        else
          parent_obj = nil
          obj = nil
        end
      end

      if obj && (counter == path_split.length)
        return obj, parent_obj
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
data_processor-0.2.1 lib/data_processor/helpers.rb
data_processor-0.2.0 lib/data_processor/helpers.rb