csv-utils 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/csv-validator +14 -1
- data/csv-utils.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b3f6bdded232bf3be2009d4bbb5ab99e083cd9f48dff5fabe89324f5217550a
|
4
|
+
data.tar.gz: 86b130f177d173a74bc1611c5677cc6bad5053e953a1a5fabfeabee494e372c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd0a299cbe4b153f122d605bbb1b2ab08726194d58010e909090048f1cef0e384d08c8a3a59683b8108c1dc3766deacac46a9063af35e57502f6fe3c92b855ff
|
7
|
+
data.tar.gz: e4233e0c38338d24a6105d465745092146a65e03f297442fabada13ecf380db70740196726ec2d40a8f92828b6cfbc6945c0274701091cb2687af549126e34fa
|
data/bin/csv-validator
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'csv'
|
4
|
-
|
4
|
+
begin
|
5
|
+
require 'rchardet'
|
6
|
+
rescue LoadError
|
7
|
+
$stderr.puts 'gem install rchardet'
|
8
|
+
exit 1
|
9
|
+
end
|
5
10
|
|
6
11
|
def utf8?(str)
|
7
12
|
str
|
@@ -21,8 +26,10 @@ def detect_encoding(col)
|
|
21
26
|
end
|
22
27
|
|
23
28
|
csv = CSV.open(ARGV[0], 'rb')
|
29
|
+
out = CSV.open(ARGV[1], 'wb') if ARGV[1]
|
24
30
|
|
25
31
|
headers = csv.shift
|
32
|
+
out << headers if out
|
26
33
|
csv_lineno = 1
|
27
34
|
|
28
35
|
while (row = csv.shift)
|
@@ -32,16 +39,22 @@ while (row = csv.shift)
|
|
32
39
|
$stderr.puts "row(#{csv_lineno}): invalid number of columns, expected #{headers.size} got #{row.size}"
|
33
40
|
end
|
34
41
|
|
42
|
+
converted = false
|
35
43
|
row.each_with_index do |col, idx|
|
36
44
|
next if utf8?(col)
|
37
45
|
|
38
46
|
$stderr.puts "row(#{csv_lineno}),col(#{idx + 1}): none UTF-8 characters found in \"#{col}\""
|
39
47
|
if (col_utf8_encoded = convert_to_utf8(col, detect_encoding(col)))
|
48
|
+
converted = true
|
40
49
|
puts "row(#{csv_lineno}),col(#{idx + 1}): converted to UTF-8 from #{detect_encoding(col)} \"#{col_utf8_encoded}\""
|
50
|
+
row[idx] = col_utf8_encoded
|
41
51
|
else
|
42
52
|
$stderr.puts "row(#{csv_lineno}),col(#{idx + 1}): unknown character encoding"
|
43
53
|
end
|
44
54
|
end
|
55
|
+
|
56
|
+
out << row if out && converted
|
45
57
|
end
|
46
58
|
|
47
59
|
csv.close
|
60
|
+
out.close if out
|
data/csv-utils.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|