Class: MaintenanceTasks::BatchCsvCollectionBuilder Private
- Inherits:
-
CsvCollectionBuilder
- Object
- CsvCollectionBuilder
- MaintenanceTasks::BatchCsvCollectionBuilder
- Defined in:
- app/models/maintenance_tasks/batch_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 in batches.
Defined Under Namespace
Classes: BatchCsv
Instance Method Summary collapse
-
#collection(task) ⇒ Object
private
Defines the collection to be iterated over, based on the provided CSV.
-
#count(task) ⇒ Integer
private
The number of batches to be processed.
-
#initialize(batch_size, **csv_options) ⇒ BatchCsvCollectionBuilder
constructor
private
Initialize a BatchCsvCollectionBuilder with a batch size.
Methods inherited from CsvCollectionBuilder
#has_csv_content?, #no_collection?
Constructor Details
#initialize(batch_size, **csv_options) ⇒ BatchCsvCollectionBuilder
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.
Initialize a BatchCsvCollectionBuilder with a batch size.
16 17 18 19 |
# File 'app/models/maintenance_tasks/batch_csv_collection_builder.rb', line 16 def initialize(batch_size, **) @batch_size = batch_size super(**) end |
Instance Method Details
#collection(task) ⇒ 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.
Defines the collection to be iterated over, based on the provided CSV. Includes the CSV and the batch size.
23 24 25 26 27 28 |
# File 'app/models/maintenance_tasks/batch_csv_collection_builder.rb', line 23 def collection(task) BatchCsv.new( csv: CSV.new(task.csv_content, **@csv_options), batch_size: @batch_size, ) 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 batches to be processed. Excludes the header row from the count and assumes a trailing newline is at the end of the CSV file. Note that this number is an approximation based on the number of newlines.
36 37 38 39 |
# File 'app/models/maintenance_tasks/batch_csv_collection_builder.rb', line 36 def count(task) count = task.csv_content.count("\n") - 1 (count + @batch_size - 1) / @batch_size end |