class Threatinator::Parsers::JSON::Adapters::Oj

Public Class Methods

new() click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 7
def initialize
  @root = nil
  @depth = 0
end

Public Instance Methods

array_append(a,v) click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 52
def array_append(a,v)
  if @depth == 1
    do_callback(v)
  else 
    a << v
  end
end
array_end() click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 60
def array_end
  @depth -= 1
end
array_start() click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 45
def array_start
  ret = []
  @depth += 1
  @root = ret if @root.nil?
  ret
end
do_callback(data, key = nil) click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 21
def do_callback(data, key = nil)
  @callback.call(data, key: key)
end
hash_end() click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 41
def hash_end
  @depth -= 1
end
hash_set(h,k,v) click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 32
def hash_set(h,k,v)
  if @depth == 1
    do_callback(v, k)
  else 
    h[k] = v
  end
  v
end
hash_start() click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 25
def hash_start
  ret = {}
  @depth += 1
  @root = ret if @root.nil?
  ret
end
run(io, &callback) click to toggle source
# File lib/threatinator/parsers/json/adapters/oj.rb, line 12
def run(io, &callback)
  @callback = callback
  begin
    ::Oj.sc_parse(self, io)
  rescue ::Oj::ParseError => e
    raise Threatinator::Exceptions::ParseError.new(e)
  end
end