class Threatinator::Parsers::JSON::Parser

Public Class Methods

adapter_class() click to toggle source

Detects the platform, loads the JSON adapter, and returns the adapter's class.

# File lib/threatinator/parsers/json/parser.rb, line 15
def self.adapter_class
  if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
    #:nocov:
    raise "JSON parsing not supported for JRuby"
    #:nocov:
  else 
    require 'threatinator/parsers/json/adapters/oj'
    return Threatinator::Parsers::JSON::Adapters::Oj
  end
end
new(opts = {}) click to toggle source
Calls superclass method Threatinator::Parser::new
# File lib/threatinator/parsers/json/parser.rb, line 8
def initialize(opts = {})
  @adapter_class = self.class.adapter_class
  super(opts)
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method Threatinator::Parser#==
# File lib/threatinator/parsers/json/parser.rb, line 26
def ==(other)
  super(other)
end
run(io) { |record| ... } click to toggle source

@param [IO] io @yield [record] Gives one line to the block @yieldparam record [Threatinator::Parsers::JSON::Record] a record

# File lib/threatinator/parsers/json/parser.rb, line 33
def run(io)
  adapter = @adapter_class.new
  callback = lambda do |object, opts = {}|
    yield Threatinator::Parsers::JSON::Record.new(object, opts)
  end
  adapter.run(io, &callback)
  nil
end