Permalink
Browse files

improve NibblerJSON with plural elements

  • Loading branch information...
1 parent 40b7ae5 commit d7aff0c46481c0029eade4b92bfa268b151c1653 @mislav committed Nov 30, 2010
Showing with 4 additions and 2 deletions.
  1. +4 −2 lib/nibbler/json.rb
View
@@ -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

0 comments on commit d7aff0c

Please sign in to comment.