Class: FlatKit::Jsonl::Reader
- Defined in:
- lib/flat_kit/jsonl/reader.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Attributes inherited from Reader
Class Method Summary collapse
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(source:, compare_fields: :none) ⇒ Reader
constructor
A new instance of Reader.
Methods inherited from Reader
create_reader_from_path, create_readers_from_paths, #format_name
Constructor Details
#initialize(source:, compare_fields: :none) ⇒ Reader
Returns a new instance of Reader.
11 12 13 14 15 |
# File 'lib/flat_kit/jsonl/reader.rb', line 11 def initialize(source:, compare_fields: :none) super @input = ::FlatKit::Input.from(source) @count = 0 end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
5 6 7 |
# File 'lib/flat_kit/jsonl/reader.rb', line 5 def count @count end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
4 5 6 |
# File 'lib/flat_kit/jsonl/reader.rb', line 4 def input @input end |
Class Method Details
.format_name ⇒ Object
7 8 9 |
# File 'lib/flat_kit/jsonl/reader.rb', line 7 def self.format_name ::FlatKit::Jsonl::Format.format_name end |
Instance Method Details
#each ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flat_kit/jsonl/reader.rb', line 17 def each while line = input.io.gets do record = ::FlatKit::Jsonl::Record.new(data: line, compare_fields: compare_fields) @count += 1 yield record end input.close rescue => e ::FlatKit.logger.error "Error reading jsonl records from #{input.name}: #{e}" raise ::FlatKit::Error, e end |