Class: Rjp::Parser
- Inherits:
-
Object
- Object
- Rjp::Parser
- Defined in:
- lib/rjp.rb
Instance Method Summary collapse
- #extract(*keys, &block) ⇒ Object
-
#initialize(json_str) ⇒ Parser
constructor
A new instance of Parser.
- #json ⇒ Object
- #to_h ⇒ Object
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 |
#json ⇒ Object
23 24 25 |
# File 'lib/rjp.rb', line 23 def json @json ||= Traversable.new(JSON.parse @raw) end |
#to_h ⇒ Object
19 20 21 |
# File 'lib/rjp.rb', line 19 def to_h json end |