csv-utils 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/csv-explorer +12 -0
- data/csv-utils.gemspec +1 -1
- data/lib/csv-utils.rb +1 -0
- data/lib/csv_utils/csv_iterator.rb +47 -0
- data/lib/csv_utils/csv_wrapper.rb +4 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc87e9b60715e648c97c91c1bbe562eb72a6fd964782abf3f1468588c053537b
|
4
|
+
data.tar.gz: c368dda5d1b829a6dff9ac934e42b716c8c704d3a4605f8c4b195d1a10bcc94e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8ead05ff26fcb2540403bcb47e5eacad33fcacf58f65ff48442406d0556f6dc5a23164258303a779a718ebc6bd8d232f6bad93d20d49275da05988bb0cc39c1
|
7
|
+
data.tar.gz: f5c9d16c15fc3af24947cb1aeb122962f26483cfba282a6676b1a47c8ecc9504952785898a0c94c771520b60fc3fbc84f3453c76ba9ebd896f0e19e546b23f69
|
data/bin/csv-explorer
ADDED
data/csv-utils.gemspec
CHANGED
data/lib/csv-utils.rb
CHANGED
@@ -3,6 +3,7 @@ require 'csv'
|
|
3
3
|
# Collection of tools for working with CSV files.
|
4
4
|
module CSVUtils
|
5
5
|
autoload :CSVExtender, 'csv_utils/csv_extender'
|
6
|
+
autoload :CSVIterator, 'csv_utils/csv_iterator'
|
6
7
|
autoload :CSVOptions, 'csv_utils/csv_options'
|
7
8
|
autoload :CSVReport, 'csv_utils/csv_report'
|
8
9
|
autoload :CSVRow, 'csv_utils/csv_row'
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Search a CSV given a series of steps
|
2
|
+
class CSVUtils::CSVIterator
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
class RowWrapper < Hash
|
6
|
+
attr_accessor :lineno
|
7
|
+
|
8
|
+
def self.create(headers, row, lineno)
|
9
|
+
row_wrapper = RowWrapper[headers.zip(row)]
|
10
|
+
row_wrapper.lineno = lineno
|
11
|
+
row_wrapper
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_pretty_s
|
15
|
+
reject { |_, v| v.strip.empty? }
|
16
|
+
.each_with_index
|
17
|
+
.map { |(k, v), idx| sprintf(' %-3d %s: %s', idx+1, k, v) }
|
18
|
+
.join("\n") + "\n"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(src_csv, csv_options = {})
|
23
|
+
@src_csv = CSVUtils::CSVWrapper.new(src_csv, 'rb', csv_options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def each(headers = nil)
|
27
|
+
@src_csv.rewind
|
28
|
+
|
29
|
+
lineno = 0
|
30
|
+
unless headers
|
31
|
+
headers = @src_csv.shift
|
32
|
+
strip_bom!(headers[0])
|
33
|
+
lineno += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
while (row = @src_csv.shift)
|
37
|
+
lineno += 1
|
38
|
+
yield RowWrapper.create(headers, row, lineno)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def strip_bom!(col)
|
45
|
+
col.sub!("\xEF\xBB\xBF".force_encoding('ASCII-8BIT'), '')
|
46
|
+
end
|
47
|
+
end
|
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.5
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inheritance-helper
|
@@ -28,6 +28,7 @@ description: Tools for debugging malformed CSV files
|
|
28
28
|
email: dougyouch@gmail.com
|
29
29
|
executables:
|
30
30
|
- csv-change-eol
|
31
|
+
- csv-explorer
|
31
32
|
- csv-find-error
|
32
33
|
- csv-readline
|
33
34
|
- csv-validator
|
@@ -42,12 +43,14 @@ files:
|
|
42
43
|
- LICENSE
|
43
44
|
- README.md
|
44
45
|
- bin/csv-change-eol
|
46
|
+
- bin/csv-explorer
|
45
47
|
- bin/csv-find-error
|
46
48
|
- bin/csv-readline
|
47
49
|
- bin/csv-validator
|
48
50
|
- csv-utils.gemspec
|
49
51
|
- lib/csv-utils.rb
|
50
52
|
- lib/csv_utils/csv_extender.rb
|
53
|
+
- lib/csv_utils/csv_iterator.rb
|
51
54
|
- lib/csv_utils/csv_options.rb
|
52
55
|
- lib/csv_utils/csv_report.rb
|
53
56
|
- lib/csv_utils/csv_row.rb
|