Class: Nibbler::JsonDocument
- Inherits:
-
Object
- Object
- Nibbler::JsonDocument
- Defined in:
- lib/nibbler/json.rb
Overview
a wrapper for JSON data that provides ‘at` and `search`
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #at(selector) ⇒ Object
-
#initialize(obj) ⇒ JsonDocument
constructor
A new instance of JsonDocument.
- #search(selector) ⇒ Object
Constructor Details
#initialize(obj) ⇒ JsonDocument
Returns a new instance of JsonDocument.
7 8 9 |
# File 'lib/nibbler/json.rb', line 7 def initialize(obj) @data = String === obj ? JSON.parse(obj) : obj end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/nibbler/json.rb', line 5 def data @data end |
Class Method Details
.[](obj) ⇒ Object
11 12 13 |
# File 'lib/nibbler/json.rb', line 11 def self.[](obj) self.class === obj ? obj : new(obj) end |
Instance Method Details
#at(selector) ⇒ Object
19 20 21 |
# File 'lib/nibbler/json.rb', line 19 def at(selector) data[selector] end |
#search(selector) ⇒ Object
15 16 17 |
# File 'lib/nibbler/json.rb', line 15 def search(selector) Array === data ? data : Array(at(selector)) end |