Class: Nibbler::JsonDocument

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

Overview

a wrapper for JSON data that provides ‘at` and `search`

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ JsonDocument

Returns a new instance of JsonDocument.



5
6
7
# File 'lib/nibbler/json.rb', line 5

def initialize(obj)
  @data = String === obj ? JSON.parse(obj) : obj
end

Class Method Details

.[](obj) ⇒ Object



9
10
11
# File 'lib/nibbler/json.rb', line 9

def self.[](obj)
  self.class === obj ? obj : new(obj)
end

Instance Method Details

#at(selector) ⇒ Object



17
18
19
# File 'lib/nibbler/json.rb', line 17

def at(selector)
  @data[selector]
end

#search(selector) ⇒ Object



13
14
15
# File 'lib/nibbler/json.rb', line 13

def search(selector)
  @data.to_a
end