Class: MaintenanceTasks::CsvCollectionBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
app/models/maintenance_tasks/csv_collection_builder.rb

Overview

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.

Strategy for building a Task that processes CSV files.

Direct Known Subclasses

BatchCsvCollectionBuilder

Instance Method Summary collapse

Constructor Details

#initialize(**csv_options) ⇒ CsvCollectionBuilder

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 CsvCollectionBuilder.



11
12
13
# File 'app/models/maintenance_tasks/csv_collection_builder.rb', line 11

def initialize(**csv_options)
  @csv_options = csv_options
end

Instance Method Details

#collection(task) ⇒ CSV

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.

Defines the collection to be iterated over, based on the provided CSV.

Returns:

  • (CSV)

    the CSV object constructed from the specified CSV content.



18
19
20
# File 'app/models/maintenance_tasks/csv_collection_builder.rb', line 18

def collection(task)
  CSV.new(task.csv_content, **@csv_options)
end

#count(task) ⇒ Integer

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.

The number of rows to be processed. It uses the CSV library for an accurate row count. Note that the entire file is loaded. It will take several seconds with files with millions of rows.

Returns:

  • (Integer)

    the approximate number of rows to process.



27
28
29
# File 'app/models/maintenance_tasks/csv_collection_builder.rb', line 27

def count(task)
  CSV.new(task.csv_content, **@csv_options).count
end

#has_csv_content?Boolean

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.

Return that the Task processes CSV content.

Returns:

  • (Boolean)


32
33
34
# File 'app/models/maintenance_tasks/csv_collection_builder.rb', line 32

def has_csv_content?
  true
end

#no_collection?Boolean

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 that the Task processes a collection.

Returns:

  • (Boolean)


37
38
39
# File 'app/models/maintenance_tasks/csv_collection_builder.rb', line 37

def no_collection?
  false
end