Class: JsonPointer::Evaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/json_pointer/evaluator.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Evaluator

Returns a new instance of Evaluator.



3
4
5
# File 'lib/json_pointer/evaluator.rb', line 3

def initialize(data)
  @data = data
end

Instance Method Details

#evaluate(original_path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/json_pointer/evaluator.rb', line 7

def evaluate(original_path)
  path = original_path

  # the leading # can either be included or not
  path = path[1..-1] if path[0] == "#"

  # special case on "" or presumably "#"
  if path.empty?
    return @data
  end

  if path[0] != "/"
    raise %{Path must begin with a leading "/": #{original_path}.}
  end

  path_parts = split(path)
  evaluate_segment(@data, path_parts)
end