splitcsv 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/splitcsv +3 -3
- data/lib/splitcsv/version.rb +1 -1
- data/lib/splitcsv.rb +1 -26
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 918a37b1e8e6b007e6983d5eef55563c76630ecb
|
4
|
+
data.tar.gz: 962ab87ce829fda71ba4caa929635d719fbf9483
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6c0b2dab6ee0cc54715b879a25a505e565429ca4181f3d3ad5f341c5fa3c9971551da8269e426cc3fa1d2446003ff910d8b2c222f320cc9a9d8855b9d43081
|
7
|
+
data.tar.gz: 44e21aacd04250d4c48918412eee8a9f3b9fff77ba3277d97e297f9def85e8048ef05c090c33618b6fce58f207498b22e84c814b0c1f9dd24839207a10297ca2
|
data/bin/splitcsv
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'splitcsv'
|
3
|
+
require 'splitcsv/splitter'
|
4
4
|
|
5
5
|
if (ARGV[0] == nil)
|
6
6
|
puts 'Usage: splitcsv <file> [<maxlength> [<separator>]]'
|
@@ -15,5 +15,5 @@ end
|
|
15
15
|
csv_maxlength = ARGV[1] || 5000
|
16
16
|
csv_colseparator = ARGV[2] || ";"
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
my_splitter = SplitCSV::Splitter.new
|
19
|
+
my_splitter.split(ARGV[0], csv_maxlength, csv_colseparator)
|
data/lib/splitcsv/version.rb
CHANGED
data/lib/splitcsv.rb
CHANGED
@@ -1,31 +1,6 @@
|
|
1
1
|
require "splitcsv/version"
|
2
|
+
require "splitcsv/splitter"
|
2
3
|
|
3
4
|
module SplitCSV
|
4
|
-
class SplitCSV
|
5
|
-
def split(file, maxlength=5000, separator=';')
|
6
|
-
csv_basename = File.basename(file, ".*")
|
7
|
-
csv_path = File.expand_path(file)
|
8
|
-
csv_dir = File.dirname(csv_path)
|
9
5
|
|
10
|
-
csv_file = CSV.open(file, :row_sep => :auto, :col_sep => separator)
|
11
|
-
csv_length = csv_file.readlines.size
|
12
|
-
|
13
|
-
# Opnieuw inlezen zodat readline pointer terug aan 0 staat. Na gebruiken van
|
14
|
-
# csv_file.readlines.size werd "csv_file" al eens volledig doorlopen
|
15
|
-
csv_file = CSV.open(file, :row_sep => :auto, :col_sep => separator)
|
16
|
-
firstline = csv_file.readline
|
17
|
-
|
18
|
-
for i in 0..((csv_length / maxlength.to_i).ceil) do
|
19
|
-
CSV.open("#{csv_dir}/#{csv_basename}_#{i+1}.csv", 'w', :row_sep => :auto, :col_sep => separator) do |csv|
|
20
|
-
csv << firstline
|
21
|
-
|
22
|
-
for j in 1..csv_maxlength do
|
23
|
-
if (line = csv_file.readline) != nil
|
24
|
-
csv << line
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
6
|
end
|