Class: Aj
- Inherits:
-
Oj::Saj
- Object
- Oj::Saj
- Aj
- Defined in:
- lib/magnum-pi/gem_ext/oj/aj.rb
Instance Method Summary collapse
- #add_value(value, key) ⇒ Object
- #array_end(key) ⇒ Object
- #array_start(key) ⇒ Object
- #each(pattern, &block) ⇒ Object
- #hash_end(key) ⇒ Object
- #hash_start(key) ⇒ Object
-
#initialize(json) ⇒ Aj
constructor
A new instance of Aj.
- #to_enum ⇒ Object
Constructor Details
#initialize(json) ⇒ Aj
Returns a new instance of Aj.
5 6 7 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 5 def initialize(json) @stringio = json.is_a?(StringIO) ? json : StringIO.new(json) end |
Instance Method Details
#add_value(value, key) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 39 def add_value(value, key) if (entry = current_entry).nil? current_path << :nokey entries << {key => value} else entry[key] = value end end |
#array_end(key) ⇒ Object
35 36 37 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 35 def array_end(key) end_enum end |
#array_start(key) ⇒ Object
27 28 29 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 27 def array_start(key) start_enum key, [], :array end |
#each(pattern, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 9 def each(pattern, &block) @pattern = pattern.split("/").collect{|x| x == "" ? "*" : x} @block = block @stringio.rewind Oj.saj_parse self, @stringio ensure @types = nil @current_path = nil @entries = nil @regexp = nil end |
#hash_end(key) ⇒ Object
31 32 33 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 31 def hash_end(key) end_enum end |
#hash_start(key) ⇒ Object
23 24 25 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 23 def hash_start(key) start_enum key, {}, :hash end |
#to_enum ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/magnum-pi/gem_ext/oj/aj.rb', line 48 def to_enum enum = nil each "*" do |entry, key| enum ||= begin if key == :nokey entry elsif key.is_a?(String) {} else [] end end enum[key] = entry if key != :nokey end enum end |