Class: FlatKit::Jsonl::Reader

Inherits:
Reader
  • Object
show all
Defined in:
lib/flat_kit/jsonl/reader.rb

Instance Attribute Summary collapse

Attributes inherited from Reader

#compare_fields, #source

Class Method Summary collapse

Instance Method Summary collapse

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

#countObject (readonly)

Returns the value of attribute count.



5
6
7
# File 'lib/flat_kit/jsonl/reader.rb', line 5

def count
  @count
end

#inputObject (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_nameObject



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

#eachObject



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