csv-utils 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/csv-change-eol +54 -0
  3. data/csv-utils.gemspec +1 -1
  4. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6af40dc417430366452f9b5ddc1670595fb16ca17ab8452b7842faaa0726343
4
- data.tar.gz: 11db2a2e86c54f4f9593113cd2f1ddd9b712213beb7da49b0660501d63c148a5
3
+ metadata.gz: 5d426e3be79ea7c3424c7778e2eb28ac750a55d0af374115021791506cfe933d
4
+ data.tar.gz: 00fec1a3995a515fca21f8032d40f9447cdbccfb53e7f22644982ff4c3d703a6
5
5
  SHA512:
6
- metadata.gz: d97f0d8b564b3819713250b52f83a2b538862654423c9d932c77a0d188199949a31ed8acaf3fd0db7c1bcc00a57c1cdde2997553c2cd062429de691354472611
7
- data.tar.gz: 1c486515fba9b72c9c37a4952f86f872947518fb82a2573e5868c57520085516f202acf146f2f276fe4fe88b20f49c304d391b30f9bdb96d8c82982d38109b03
6
+ metadata.gz: d560c6b227162d297f396213cb26b277b437dc744a05f072f9f5716ea6920ff35dbedcdfcd544e4b5b8589f0e8e1322e79b5cdcb63d9d9e5f26019c141d77772
7
+ data.tar.gz: 7fd77c041baefdc87e4166781739bd97dc1183824414cb928c4a369adb972423d460f67562f848ac4373fb1c19cde9d962ee73a554590b0950d0bc9462e42b52
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'csv'
4
+
5
+ def bold_string(str)
6
+ "\033[1m#{str}\033[0m"
7
+ end
8
+
9
+ USAGE = "Usage: #{bold_string('csv-change-eol')} <csv_file> <end of line character sequence in hex>"
10
+
11
+ def exit_on_error(msg)
12
+ $stderr.print <<STR
13
+ Error: #{bold_string(msg)}
14
+
15
+ #{USAGE}
16
+
17
+ End of line example: '7C5E7C0A' is '|^|\\n'
18
+ - 0A is new line
19
+ - 0D is carriage return
20
+
21
+ Goto: #{bold_string('http://www.asciitable.com/')} for help with the character sequence
22
+
23
+ STR
24
+ exit 1
25
+ end
26
+
27
+ csv_file = ARGV.shift || exit_on_error('no csv file specified')
28
+ eol_sequence = ARGV.shift || exit_on_error('no EOL character sequence specified')
29
+
30
+ exit_on_error("file #{csv_file} not found") unless File.exist?(csv_file)
31
+ exit_on_error("not a HEX sequece (#{eol_sequence})") unless eol_sequence =~ /\A[0-9a-f]+\z/i
32
+ exit_on_error("incorrect number of characters in (#{eol_sequence}), should be even") unless eol_sequence.size.even?
33
+
34
+ eol_sequence = [eol_sequence].pack('H*')
35
+
36
+
37
+ escaped_csv_file =
38
+ if csv_file =~ /\.csv$/i
39
+ csv_file.sub(/(\.csv)$/i, '.escaped-eol\1')
40
+ else
41
+ csv_file + '.escaped-eol'
42
+ end
43
+
44
+
45
+ File.open(escaped_csv_file, 'wb') do |out|
46
+ CSV.foreach(csv_file) do |row|
47
+ line = row.to_csv
48
+ line.rstrip!
49
+ line.concat(eol_sequence)
50
+ out.write line
51
+ end
52
+ end
53
+
54
+ puts escaped_csv_file
data/csv-utils.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'csv-utils'
5
- s.version = '0.1.6'
5
+ s.version = '0.1.7'
6
6
  s.summary = 'CSV Utils'
7
7
  s.description = 'Tools for debugging malformed CSV files'
8
8
  s.authors = ['Doug Youch']
metadata CHANGED
@@ -1,18 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-30 00:00:00.000000000 Z
11
+ date: 2020-03-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Tools for debugging malformed CSV files
14
14
  email: dougyouch@gmail.com
15
15
  executables:
16
+ - csv-change-eol
16
17
  - csv-find-error
17
18
  - csv-readline
18
19
  extensions: []
@@ -21,6 +22,7 @@ files:
21
22
  - ".gitignore"
22
23
  - LICENSE
23
24
  - README.md
25
+ - bin/csv-change-eol
24
26
  - bin/csv-find-error
25
27
  - bin/csv-readline
26
28
  - csv-utils.gemspec
@@ -42,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
44
  - !ruby/object:Gem::Version
43
45
  version: '0'
44
46
  requirements: []
45
- rubygems_version: 3.0.3
47
+ rubygems_version: 3.0.8
46
48
  signing_key:
47
49
  specification_version: 4
48
50
  summary: CSV Utils