splitcsv 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/splitcsv/splitter.rb +31 -0
- data/lib/splitcsv/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0afa9840aef4bf7f83ea14e82374cef5d8bf56e1
|
4
|
+
data.tar.gz: 5850351d69e24212513e5daeac10bfb0dc03c0d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49bc9a0f43c2b96f22ce536b829efd2f086b6d36377ba2f0a9640f84d2d53b66532326124b38ec1f23b585a0838105a19df1da8cc77888da4c798ee86ff97e28
|
7
|
+
data.tar.gz: 5c2242bc7952d4c329aa12c31089d2621cd54f5397004a9a3998ee1562cf5a4ba45580caf89cd37e5de8e78c4eaa1e6555d95ef2f651787243b2b6185dd2c5cb
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'CSV'
|
2
|
+
|
3
|
+
module SplitCSV
|
4
|
+
class Splitter
|
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
|
+
|
10
|
+
csv_obj = CSV.open(csv_path, :row_sep => :auto, :col_sep => separator)
|
11
|
+
csv_length = csv_obj.readlines.size
|
12
|
+
|
13
|
+
# Opnieuw inlezen zodat readline pointer terug aan 0 staat. Na gebruiken van
|
14
|
+
# csv_obj.readlines.size werd "csv_obj" al eens volledig doorlopen
|
15
|
+
csv_obj = CSV.open(csv_path, :row_sep => :auto, :col_sep => separator)
|
16
|
+
firstline = csv_obj.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 0..maxlength.to_i do
|
23
|
+
if (line = csv_obj.readline) != nil
|
24
|
+
csv << line
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/splitcsv/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: splitcsv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bert Devriese
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- Rakefile
|
55
55
|
- bin/splitcsv
|
56
56
|
- lib/splitcsv.rb
|
57
|
+
- lib/splitcsv/splitter.rb
|
57
58
|
- lib/splitcsv/version.rb
|
58
59
|
- splitcsv.gemspec
|
59
60
|
homepage: http://www.builtinbruges.com
|