module Hana VERSION = '1.1.0' class Pointer include Enumerable def initialize path @path = Pointer.parse path end def each(&block); @path.each(&block); end def to_a; @path.dup; end def eval object Pointer.eval @path, object end ESC = {'^/' => '/', '^^' => '^', '~0' => '~', '~1' => '/'} # :nodoc: def self.eval list, object list.inject(object) { |o, part| o[(Array === o ? part.to_i : part)] } end def self.parse path return [''] if path == '/' path.sub(/^\//, '').split(/(? obj.length || idx < 0 idx end def add_op dest, key, obj if Array === dest dest.insert check_index(dest, key), obj else dest[key] = obj end end def rm_op obj, key if Array === obj obj.delete_at key.to_i else obj.delete key end end end end