Skip to content

Commit

Permalink
Fixed tilo#18
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Running committed Sep 26, 2013
1 parent cca8b23 commit 029af93
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions lib/smarter_csv/smarter_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,29 @@ def SmarterCSV.process(input, options={}, &block) # first parameter: filename
end
end
end
next if hash.empty? if options[:remove_empty_hashes]

if use_chunks
chunk << hash # append temp result to chunk

if chunk.size >= chunk_size || f.eof? # if chunk if full, or EOF reached
# do something with the chunk
unless hash.empty? && options[:remove_empty_hashes]
if use_chunks
chunk << hash
next unless chunk.size >= chunk_size || f.eof? # finish chunk unless chunk is full, or EOF is reached
else
if block_given?
yield chunk # do something with the hashes in the chunk in the block
yield [hash] # do something with the hash in the block (better to use chunking here)
else
result << chunk # not sure yet, why anybody would want to do this without a block
result << hash
end
chunk_count += 1
chunk = [] # initialize for next chunk of data
end
# while a chunk is being filled up we don't need to do anything else here
end
next unless use_chunks

else # no chunk handling
if block_given?
yield [hash] # do something with the hash in the block (better to use chunking here)
else
result << hash
end
# do something with the chunk
if block_given?
yield chunk # do something with the hashes in the chunk in the block
else
result << chunk # not sure yet, why anybody would want to do this without a block
end
chunk_count += 1
chunk = [] # initialize for next chunk of data
end
ensure
$/ = old_row_sep # make sure this stupid global variable is always reset to it's previous value after we're done!
Expand Down

0 comments on commit 029af93

Please sign in to comment.