censive 0.21 → 0.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/censive.gemspec +1 -1
- data/lib/censive.rb +15 -11
- metadata +2 -6
- data/diagram/NFA to Regex.pdf +0 -0
- data/lib/test-censive.rb +0 -12
- data/lib/test-csv.rb +0 -12
- data/test/a-uses-tabs-and-single-quotes-and-no-trailing-newline.tsv +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a787932ff608f1df361b6faca419ce69eac2cafe853aa7c16155c5f2ace4621
|
4
|
+
data.tar.gz: 1818249a3e778223297adaff85216c6497d2f802c25e77664ec1525e51dc9d2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ecf977a34e9cd5f86fdc8843aa64b2212bcf608a30eef579593e5af5d3c9ab00164d0dac1030738898ccfe4b541366d711ac8a029b2f907071c113543d10003
|
7
|
+
data.tar.gz: 90780a1b7ca9be28eb7e83392ba00f0d4a7374c05b91845605cf9f8c64d58d5e187d468de96dfabe2126f331944ca94b4d4f5af286750c054db13731bfe8830d
|
data/censive.gemspec
CHANGED
data/lib/censive.rb
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
# censive - A quick and lightweight CSV handling library for Ruby
|
5
5
|
#
|
6
6
|
# Author: Steve Shreeve (steve.shreeve@gmail.com)
|
7
|
-
# Date: Feb
|
7
|
+
# Date: Feb 17, 2023
|
8
8
|
#
|
9
9
|
# https://crystal-lang.org/api/1.7.2/CSV.html (Crystal's CSV library)
|
10
10
|
# https://github.com/ruby/strscan/blob/master/ext/strscan/strscan.c
|
@@ -28,7 +28,7 @@
|
|
28
28
|
require "strscan"
|
29
29
|
|
30
30
|
class Censive < StringScanner
|
31
|
-
attr :encoding, :out
|
31
|
+
attr :encoding, :out, :rows
|
32
32
|
|
33
33
|
def self.parse(...)
|
34
34
|
new(...).parse
|
@@ -46,11 +46,11 @@ class Censive < StringScanner
|
|
46
46
|
drop: false , # drop trailing empty columns?
|
47
47
|
encoding: nil , # character encoding
|
48
48
|
excel: false , # literals ="01" formulas =A1 + B2 http://bit.ly/3Y7jIvc
|
49
|
-
mode: :compact, #
|
49
|
+
mode: :compact, # output mode: compact or full
|
50
50
|
out: nil , # output stream, needs to respond to <<
|
51
51
|
quote: '"' , # quote character
|
52
52
|
relax: false , # relax quote parsing so ,"Fo"o, => ,"Fo""o",
|
53
|
-
rowsep: "\n" , # row separator for
|
53
|
+
rowsep: "\n" , # row separator for output
|
54
54
|
sep: "," , # column separator character
|
55
55
|
strip: false , # strip columns when reading
|
56
56
|
**opts # grab bag
|
@@ -71,7 +71,7 @@ class Censive < StringScanner
|
|
71
71
|
@encoding = str.encoding
|
72
72
|
@excel = excel
|
73
73
|
@mode = mode
|
74
|
-
@out = out ||
|
74
|
+
@out = out || ""
|
75
75
|
@relax = relax
|
76
76
|
@strip = strip
|
77
77
|
|
@@ -121,7 +121,7 @@ class Censive < StringScanner
|
|
121
121
|
@cols = count if count > @cols
|
122
122
|
@cells += count
|
123
123
|
end
|
124
|
-
|
124
|
+
self
|
125
125
|
end
|
126
126
|
|
127
127
|
def next_row
|
@@ -179,10 +179,10 @@ class Censive < StringScanner
|
|
179
179
|
@rows.each {|row| yield row }
|
180
180
|
end
|
181
181
|
|
182
|
-
def
|
183
|
-
|
184
|
-
each {|row|
|
185
|
-
|
182
|
+
def to_csv(**opts)
|
183
|
+
dest = opts.empty? ? self : self.class.writer(**opts)
|
184
|
+
each {|row| dest << row }
|
185
|
+
dest.out
|
186
186
|
end
|
187
187
|
|
188
188
|
# ==[ Helpers ]==
|
@@ -259,7 +259,11 @@ if __FILE__ == $0
|
|
259
259
|
# csv.export(out: out) # (excel: true) # sep: "|")
|
260
260
|
# puts out # .string
|
261
261
|
|
262
|
-
|
262
|
+
# csv = Censive.new(str, excel: true, relax: true, out: "")
|
263
|
+
# out = csv.export
|
264
|
+
# puts out.out
|
265
|
+
|
266
|
+
Censive.parse(str, excel: true, relax: true).to_csv
|
263
267
|
end
|
264
268
|
|
265
269
|
__END__
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: censive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.23'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A quick and lightweight CSV handling library for Ruby
|
14
14
|
email: steve.shreeve@gmail.com
|
@@ -19,7 +19,6 @@ files:
|
|
19
19
|
- LICENSE
|
20
20
|
- README.md
|
21
21
|
- censive.gemspec
|
22
|
-
- diagram/NFA to Regex.pdf
|
23
22
|
- diagram/censive@ce9d51d.png
|
24
23
|
- diagram/csv-ragel.dot
|
25
24
|
- diagram/csv.dot
|
@@ -29,9 +28,6 @@ files:
|
|
29
28
|
- diagram/diagram.dot
|
30
29
|
- diagram/diagram.rl
|
31
30
|
- lib/censive.rb
|
32
|
-
- lib/test-censive.rb
|
33
|
-
- lib/test-csv.rb
|
34
|
-
- test/a-uses-tabs-and-single-quotes-and-no-trailing-newline.tsv
|
35
31
|
homepage: https://github.com/shreeve/censive
|
36
32
|
licenses:
|
37
33
|
- MIT
|
data/diagram/NFA to Regex.pdf
DELETED
Binary file
|
data/lib/test-censive.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "./censive"
|
4
|
-
require "digest/md5"
|
5
|
-
|
6
|
-
path = ARGV[0] || "KEN_ALL.CSV"
|
7
|
-
mode = path =~ /^ken/i ? "r:cp932" : "r"
|
8
|
-
|
9
|
-
data = File.open(path, mode).read
|
10
|
-
rows = Censive.parse(data)
|
11
|
-
|
12
|
-
puts "%s %s (%d size)" % [Digest::MD5.hexdigest(rows.join), path, File.stat(path).size], ""
|
data/lib/test-csv.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "csv"
|
4
|
-
require "digest/md5"
|
5
|
-
|
6
|
-
path = ARGV[0] || "KEN_ALL.CSV"
|
7
|
-
mode = path =~ /^ken/i ? "r:cp932" : "r"
|
8
|
-
|
9
|
-
data = File.open(path, mode).read
|
10
|
-
rows = CSV.parse(data)
|
11
|
-
|
12
|
-
puts "%s %s (%d size)" % [Digest::MD5.hexdigest(rows.join), path, File.stat(path).size], ""
|