Class: Fibrio::Parsers::NDJSON
- Defined in:
- lib/fibrio/parsers/ndjson.rb
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
Methods inherited from Base
Constructor Details
This class inherits a constructor from Fibrio::Parsers::Base
Instance Method Details
#run {|record| ... } ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fibrio/parsers/ndjson.rb', line 9 def run(&emit) line_number = 0 while (line = @source.next_line) line_number += 1 next if line.strip.empty? begin emit.call(::JSON.parse(line)) rescue ::JSON::ParserError => e raise ParseError.new("invalid JSON on line #{line_number}: #{e.}", position: @source.position) end end end |