4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/cli_csv/splitter.rb', line 4
def self.split(path, division)
written = Array.new
= Array.new
= false
filename = path.split('/')[-1].split('.csv')[0]
puts filename
counter = 0
newcsv = CSV.open("#{filename}_#{counter}.csv", "wb")
CSV.foreach(File.path(path)) do |col|
counter += 1
if == false
.push(col)
= true
end
if (counter % division == 0)
newcsv.close
newcsv = CSV.open("#{filename}_#{counter / division}.csv", "wb")
.each { |i| newcsv << i }
end
newcsv << col.each { |i| [i.to_s] }
end
newcsv.close
end
|