Class: Sidekiq::Job::Iterable::CsvEnumerator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/job/iterable/csv_enumerator.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(csv) ⇒ CsvEnumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CsvEnumerator.



8
9
10
11
12
13
14
# File 'lib/sidekiq/job/iterable/csv_enumerator.rb', line 8

def initialize(csv)
  unless defined?(CSV) && csv.instance_of?(CSV)
    raise ArgumentError, "CsvEnumerator.new takes CSV object"
  end

  @csv = csv
end

Instance Method Details

#batches(cursor:, batch_size: 100) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
26
27
28
29
# File 'lib/sidekiq/job/iterable/csv_enumerator.rb', line 23

def batches(cursor:, batch_size: 100)
  @csv.lazy
    .each_slice(batch_size)
    .with_index
    .drop(cursor || 0)
    .to_enum { (count_of_rows_in_file.to_f / batch_size).ceil }
end

#rows(cursor:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
19
20
21
# File 'lib/sidekiq/job/iterable/csv_enumerator.rb', line 16

def rows(cursor:)
  @csv.lazy
    .each_with_index
    .drop(cursor || 0)
    .to_enum { count_of_rows_in_file }
end