Class: TreasureData::FileReader::JSONParser

Inherits:
Object
  • Object
show all
Defined in:
lib/td/file_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(reader, error, opts) ⇒ JSONParser

Returns a new instance of JSONParser.



114
115
116
117
118
# File 'lib/td/file_reader.rb', line 114

def initialize(reader, error, opts)
  require 'json'  # TODO yajl?
  @reader = reader
  @error = error
end

Instance Method Details

#forwardObject



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/td/file_reader.rb', line 120

def forward
  while true
    line = @reader.forward_row
    begin
      return JSON.parse(line)
    rescue
      @error.call("invalid json format: #{$!}", line)
      next
    end
  end
end