Class: CSVUtils::CSVSort
- Inherits:
-
Object
- Object
- CSVUtils::CSVSort
- Defined in:
- lib/csv_utils/csv_sort.rb
Overview
Utility class for sorting the rows for a csv file
Instance Attribute Summary collapse
-
#csv_file ⇒ Object
readonly
Returns the value of attribute csv_file.
-
#csv_options ⇒ Object
readonly
Returns the value of attribute csv_options.
-
#has_headers ⇒ Object
readonly
Returns the value of attribute has_headers.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#new_csv_file ⇒ Object
readonly
Returns the value of attribute new_csv_file.
Instance Method Summary collapse
-
#initialize(csv_file, new_csv_file, has_headers = true, csv_options = {}) ⇒ CSVSort
constructor
A new instance of CSVSort.
- #sort(batch_size = 100_000, &block) ⇒ Object
Constructor Details
#initialize(csv_file, new_csv_file, has_headers = true, csv_options = {}) ⇒ CSVSort
Returns a new instance of CSVSort.
11 12 13 14 15 16 17 18 |
# File 'lib/csv_utils/csv_sort.rb', line 11 def initialize(csv_file, new_csv_file, has_headers = true, = {}) @csv_file = csv_file @new_csv_file = new_csv_file @has_headers = has_headers @csv_options = @csv_part_files = [] @files_to_delete = [] end |
Instance Attribute Details
#csv_file ⇒ Object (readonly)
Returns the value of attribute csv_file.
5 6 7 |
# File 'lib/csv_utils/csv_sort.rb', line 5 def csv_file @csv_file end |
#csv_options ⇒ Object (readonly)
Returns the value of attribute csv_options.
5 6 7 |
# File 'lib/csv_utils/csv_sort.rb', line 5 def @csv_options end |
#has_headers ⇒ Object (readonly)
Returns the value of attribute has_headers.
5 6 7 |
# File 'lib/csv_utils/csv_sort.rb', line 5 def has_headers @has_headers end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/csv_utils/csv_sort.rb', line 5 def headers @headers end |
#new_csv_file ⇒ Object (readonly)
Returns the value of attribute new_csv_file.
5 6 7 |
# File 'lib/csv_utils/csv_sort.rb', line 5 def new_csv_file @new_csv_file end |
Instance Method Details
#sort(batch_size = 100_000, &block) ⇒ Object
20 21 22 23 |
# File 'lib/csv_utils/csv_sort.rb', line 20 def sort(batch_size = 100_000, &block) create_sorted_csv_part_files(batch_size, &block) merge_csv_part_files(&block) end |