Class: Rjp::Parser

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

Instance Method Summary collapse

Constructor Details

#initialize(json_str) ⇒ Parser

Returns a new instance of Parser.



11
12
13
# File 'lib/rjp.rb', line 11

def initialize(json_str)
  @raw = json_str
end

Instance Method Details

#extract(*keys, &block) ⇒ Object



15
16
17
# File 'lib/rjp.rb', line 15

def extract(*keys, &block)
  json.traverse(*keys, &block)
end

#jsonObject



23
24
25
# File 'lib/rjp.rb', line 23

def json
  @json ||= Traversable.new(JSON.parse @raw)
end

#to_hObject



19
20
21
# File 'lib/rjp.rb', line 19

def to_h
  json
end