class Hana::Pointer

Public Class Methods

eval(list, object) click to toggle source
# File lib/hana.rb, line 27
def self.eval list, object
  list.inject(object) { |o, part|
    return nil unless o

    if Array === o
      raise Patch::IndexError unless part =~ /\A(?:\d|[1-9]\d+)\Z/
      part = part.to_i
    end
    o[part]
  }
end
new(path) click to toggle source
# File lib/hana.rb, line 15
def initialize path
  @path = Pointer.parse path
end
parse(path) click to toggle source
# File lib/hana.rb, line 39
def self.parse path
  return [''] if path == '/'
  return []   if path == ''

  unless path.start_with? '/'
    raise FormatError, "JSON Pointer should start with a slash"
  end

  parts = path.sub(/^\//, '').split(/(?<!\^)\//).each { |part|
    part.gsub!(/\^[\/^]|~[01]/) { |m| ESC[m] }
  }

  parts.push("") if path[-1] == '/'
  parts
end

Public Instance Methods

each(&block) click to toggle source
# File lib/hana.rb, line 19
def each(&block); @path.each(&block); end
eval(object) click to toggle source
# File lib/hana.rb, line 21
def eval object
  Pointer.eval @path, object
end