csv-utils 0.1.5 → 0.1.6

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-readline +22 -3
  3. data/csv-utils.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48b1bf2dfbd79b8035b19d96af6a0fb06d55c8b6abdfeaeb7f7c3f561985aed7
4
- data.tar.gz: 63257717b646afe688126a8323a1d839ee52cc9332837c53d4bc003c1d9c82d5
3
+ metadata.gz: b6af40dc417430366452f9b5ddc1670595fb16ca17ab8452b7842faaa0726343
4
+ data.tar.gz: 11db2a2e86c54f4f9593113cd2f1ddd9b712213beb7da49b0660501d63c148a5
5
5
  SHA512:
6
- metadata.gz: 2d1e351a8b331c68b28b8cc392b8607412cef3e7d529a959b5175afce720054434b3aa3d70d18e1a30dd0765e1afa0c48813fb495f183d963e51152010f1a7f9
7
- data.tar.gz: b47d36f27c3657197eebc71145302edd4fce1a813b011fae3b4442a093e1eacc2bcaa032d021d542bb7eaed8f0c3ef37f4d373b9627161aae82dd48f0b7e2225
6
+ metadata.gz: d97f0d8b564b3819713250b52f83a2b538862654423c9d932c77a0d188199949a31ed8acaf3fd0db7c1bcc00a57c1cdde2997553c2cd062429de691354472611
7
+ data.tar.gz: 1c486515fba9b72c9c37a4952f86f872947518fb82a2573e5868c57520085516f202acf146f2f276fe4fe88b20f49c304d391b30f9bdb96d8c82982d38109b03
data/bin/csv-readline CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
4
+
3
5
  BYTE_ORDER_MARKS = {
4
6
  "\xEF\xBB\xBF".force_encoding('ASCII-8BIT') => 'UTF-8',
5
7
  "\xFE\xFF".force_encoding('ASCII-8BIT') => 'UTF-16',
@@ -25,7 +27,7 @@ def csv_parse_line(line)
25
27
  last_comma_pos = -1
26
28
  column = 1
27
29
 
28
- while pos = line.index(/([",])/, pos + 1)
30
+ while pos = line.index(/([",\n])/, pos + 1)
29
31
  case line[pos]
30
32
  when '"'
31
33
  if opened_quote
@@ -62,7 +64,8 @@ def csv_parse_line(line)
62
64
  opened_quote = true
63
65
  end
64
66
  end
65
- when ','
67
+ when ',',
68
+ "\n"
66
69
  if ! opened_quote
67
70
  column += 1
68
71
  columns << [line[last_comma_pos + 1, pos - last_comma_pos - 1], :ok]
@@ -95,6 +98,22 @@ def parse_csv_row(file, lineno, number_of_lines)
95
98
  csv_parse_line(str)
96
99
  end
97
100
 
101
+ options = {
102
+ all_columns: false
103
+ }
104
+ OptionParser.new do |opts|
105
+ opts.banner = 'Usage: ' + File.basename(__FILE__) + ' [options] <csv file> <line number> [<number of lines>]'
106
+
107
+ opts.on('-h', '--help', 'Prints this help') do
108
+ puts opts
109
+ exit
110
+ end
111
+
112
+ opts.on('-a', '--all', 'Display all columns') do
113
+ options[:all_columns] = true
114
+ end
115
+ end.parse!
116
+
98
117
  file = File.open(ARGV[0], 'rb')
99
118
  lineno = ARGV[1].to_i
100
119
  number_of_lines = (ARGV[2] || 1).to_i
@@ -109,7 +128,7 @@ file.close
109
128
  cnt = 0
110
129
  data.each do |k, (v, status)|
111
130
  cnt += 1
112
- next if empty_column?(v)
131
+ next if !options[:all_columns] && empty_column?(v)
113
132
  if status == :ok
114
133
  puts sprintf(' %-3d %s: %s', cnt, k, v)
115
134
  else
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.5'
5
+ s.version = '0.1.6'
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
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-06-19 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Tools for debugging malformed CSV files
14
14
  email: dougyouch@gmail.com