Class: Csvtool::Infrastructure::CSV::RowStreamer

Inherits:
Object
  • Object
show all
Defined in:
lib/csvtool/infrastructure/csv/row_streamer.rb

Instance Method Summary collapse

Instance Method Details

#each_in_range(file_path:, col_sep:, start_row:, end_row:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/csvtool/infrastructure/csv/row_streamer.rb', line 9

def each_in_range(file_path:, col_sep:, start_row:, end_row:)
  row_index = 0
  matched = false

  ::CSV.foreach(file_path, headers: true, col_sep: col_sep) do |row|
    row_index += 1
    next if row_index < start_row
    break if row_index > end_row

    matched = true
    yield row.fields
  end

  { matched: matched, row_count: row_index }
end