class Sidekiq::Job::Iterable::CsvEnumerator

@api private

def batches(cursor:, batch_size: 100)

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

def count_of_rows_in_file

def count_of_rows_in_file
  filepath = @csv.path
  return unless filepath
  count = IO.popen(["wc", "-l", filepath]) do |out|
    out.read.strip.to_i
  end
  count -= 1 if @csv.headers
  count
end

def initialize(csv)

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

def rows(cursor:)

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