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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 918a37b1e8e6b007e6983d5eef55563c76630ecb
4
- data.tar.gz: 962ab87ce829fda71ba4caa929635d719fbf9483
3
+ metadata.gz: 0afa9840aef4bf7f83ea14e82374cef5d8bf56e1
4
+ data.tar.gz: 5850351d69e24212513e5daeac10bfb0dc03c0d4
5
5
  SHA512:
6
- metadata.gz: 5c6c0b2dab6ee0cc54715b879a25a505e565429ca4181f3d3ad5f341c5fa3c9971551da8269e426cc3fa1d2446003ff910d8b2c222f320cc9a9d8855b9d43081
7
- data.tar.gz: 44e21aacd04250d4c48918412eee8a9f3b9fff77ba3277d97e297f9def85e8048ef05c090c33618b6fce58f207498b22e84c814b0c1f9dd24839207a10297ca2
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
@@ -1,3 +1,3 @@
1
1
  module Splitcsv
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
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.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