Class: ChunkyCsv::FileSplitter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_filename, chunk_size, output_directory) ⇒ FileSplitter

Returns a new instance of FileSplitter.



9
10
11
12
13
14
# File 'lib/chunky_csv.rb', line 9

def initialize( input_filename, chunk_size, output_directory )
  @chunk_number = 0
  @input_filename = input_filename
  @chunk_size = chunk_size
  @output_directory = output_directory
end

Instance Attribute Details

#chunk_numberObject (readonly)

Returns the value of attribute chunk_number.



7
8
9
# File 'lib/chunky_csv.rb', line 7

def chunk_number
  @chunk_number
end

#chunk_sizeObject (readonly)

Returns the value of attribute chunk_size.



7
8
9
# File 'lib/chunky_csv.rb', line 7

def chunk_size
  @chunk_size
end

#input_filenameObject (readonly)

Returns the value of attribute input_filename.



7
8
9
# File 'lib/chunky_csv.rb', line 7

def input_filename
  @input_filename
end

#output_directoryObject (readonly)

Returns the value of attribute output_directory.



7
8
9
# File 'lib/chunky_csv.rb', line 7

def output_directory
  @output_directory
end

Instance Method Details

#splitObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/chunky_csv.rb', line 16

def split()
  batch = []
  IO.foreach( input_filename ) do |line|
    batch << line

    if batch.size >= self.chunk_size
      flush_batch( batch )
      batch = []
    end
  end

  flush_batch( batch )
end