class Oj::ArrayParser

Constants

VERSION

Public Class Methods

enumerator(string_or_io, options = {}) click to toggle source

@param [String, IO] string_or_io json to parse @param [Hash] options parsing options to pass to Oj, see www.ohler.com/oj/#label-Options @return [Enumerator] yields parsed top-level entries in the read json document

# File lib/oj/array_parser.rb, line 11
def self.enumerator(string_or_io, options = {})
  Enumerator.new do |yielder|
    parser = new { |value| yielder << value }

    Oj.sc_parse(parser, string_or_io, options)
  end
end
new(&block) click to toggle source
# File lib/oj/array_parser.rb, line 19
def initialize(&block)
  @block = block
  @array_count = 0
end

Public Instance Methods

array_append(array, value) click to toggle source
# File lib/oj/array_parser.rb, line 44
def array_append(array, value)
  if @array_count == 1
    @block.call(value)
  else
    array << value
  end
end
array_end() click to toggle source
# File lib/oj/array_parser.rb, line 40
def array_end
  @array_count -= 1
end
array_start() click to toggle source
# File lib/oj/array_parser.rb, line 32
def array_start
  @array_count += 1

  if @array_count > 1
    []
  end
end
error(message, line, column) click to toggle source
# File lib/oj/array_parser.rb, line 52
def error(message, line, column)
  raise ParserError, "line: #{line}, column: #{column}, message: #{message}"
end
hash_set(hash, key, value) click to toggle source
# File lib/oj/array_parser.rb, line 28
def hash_set(hash, key, value)
  hash[key] = value
end
hash_start() click to toggle source
# File lib/oj/array_parser.rb, line 24
def hash_start
  {}
end