Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve NibblerJSON with plural elements

  • Loading branch information...
commit d7aff0c46481c0029eade4b92bfa268b151c1653 1 parent 40b7ae5
@mislav authored
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/nibbler/json.rb
View
6 lib/nibbler/json.rb
@@ -2,6 +2,8 @@
# a wrapper for JSON data that provides `at` and `search`
class Nibbler::JsonDocument
+ attr_reader :data
+
def initialize(obj)
@data = String === obj ? JSON.parse(obj) : obj
end
@@ -11,11 +13,11 @@ def self.[](obj)
end
def search(selector)
- @data.to_a
+ Array === data ? data : at(selector)
end
def at(selector)
- @data[selector]
+ data[selector]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.