Class: ChunkyCsv::FileSplitter
- Inherits:
-
Object
- Object
- ChunkyCsv::FileSplitter
- Defined in:
- lib/chunky_csv.rb
Instance Attribute Summary collapse
-
#chunk_number ⇒ Object
readonly
Returns the value of attribute chunk_number.
-
#chunk_size ⇒ Object
readonly
Returns the value of attribute chunk_size.
-
#input_filename ⇒ Object
readonly
Returns the value of attribute input_filename.
-
#output_directory ⇒ Object
readonly
Returns the value of attribute output_directory.
Instance Method Summary collapse
-
#initialize(input_filename, chunk_size, output_directory) ⇒ FileSplitter
constructor
A new instance of FileSplitter.
- #split ⇒ Object
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_number ⇒ Object (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_size ⇒ Object (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_filename ⇒ Object (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_directory ⇒ Object (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
#split ⇒ Object
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 |