Class: CSVUtils::CSVSort

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_utils/csv_sort.rb

Overview

Utility class for sorting the rows for a csv file

Instance Attribute Summary collapse

Instance Method Summary collapse

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_options = {})
  @csv_file = csv_file
  @new_csv_file = new_csv_file
  @has_headers = has_headers
  @csv_options = csv_options
  @csv_part_files = []
  @files_to_delete = []
end

Instance Attribute Details

#csv_fileObject (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_optionsObject (readonly)

Returns the value of attribute csv_options.



5
6
7
# File 'lib/csv_utils/csv_sort.rb', line 5

def csv_options
  @csv_options
end

#has_headersObject (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

#headersObject (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_fileObject (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