censive 0.25 → 0.27
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 +48 -8
- 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: dc8277614e4b254907b5d127eddae62757c4522785a9564ace4207e0bda1c1f6
|
4
|
+
data.tar.gz: 47049fc05225b53909c827b359d2201d9e0b915a21cd604625cb1cd3d2f1b1d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d904a4b70401c772e14dac76ebd8a62f88e5d6a3efd49916733eea049d613c29d3f23703a458893fd86391c668a713baadb242bee83f3909d7e18a609bd1081a
|
7
|
+
data.tar.gz: 11ea3270797dd9a9f4f994599d9324c0b23955fb8c86a01cf56378a07d94818cf922bf00f556f2100da27660412b29279b7222834dcc3ff59037fda0db920443
|
data/censive.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "censive"
|
3
|
-
s.version = `grep '
|
3
|
+
s.version = `grep -m 1 '^\s*VERSION' lib/censive.rb | head -1 | cut -f 2 -d '"'`
|
4
4
|
s.author = "Steve Shreeve"
|
5
5
|
s.email = "steve.shreeve@gmail.com"
|
6
6
|
s.summary =
|
data/lib/censive.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
VERSION="0.25"
|
4
|
-
|
5
3
|
# ============================================================================
|
6
4
|
# censive - A quick and lightweight CSV handling library for Ruby
|
7
5
|
#
|
8
6
|
# Author: Steve Shreeve (steve.shreeve@gmail.com)
|
9
|
-
# Date:
|
7
|
+
# Date: Mar 20, 2023
|
10
8
|
#
|
11
9
|
# https://crystal-lang.org/api/1.7.2/CSV.html (Crystal's CSV library)
|
12
10
|
# https://github.com/ruby/strscan/blob/master/ext/strscan/strscan.c
|
@@ -30,6 +28,8 @@ VERSION="0.25"
|
|
30
28
|
require "strscan"
|
31
29
|
|
32
30
|
class Censive < StringScanner
|
31
|
+
VERSION="0.27"
|
32
|
+
|
33
33
|
attr :encoding, :out, :rows
|
34
34
|
|
35
35
|
def self.parse(...)
|
@@ -93,14 +93,15 @@ class Censive < StringScanner
|
|
93
93
|
@seq = [@sep, @eq].join # used for parsing in excel mode
|
94
94
|
|
95
95
|
# regexes
|
96
|
-
|
96
|
+
xsep = Regexp.escape(@sep) # may need to be escaped
|
97
|
+
@eoc = /(?=#{"\\" + xsep}|#{@cr}|#{@lf}|\z)/o # end of cell
|
97
98
|
@eol = /#{@cr}#{@lf}?|#{@lf}/o # end of line
|
98
|
-
@escapes = /(#{@quote})|#{"\\"
|
99
|
-
@quotable = /#{"\\"
|
99
|
+
@escapes = /(#{@quote})|#{"\\"+xsep}|#{@cr}|#{@lf}/o
|
100
|
+
@quotable = /#{"\\"+xsep}|#{@cr}|#{@lf}/o
|
100
101
|
@quotes = /#{@quote}/o
|
101
|
-
@seps = /#{
|
102
|
+
@seps = /#{xsep}+/o
|
102
103
|
@quoted = @excel ? /(?:=)?#{@quote}/o : @quote
|
103
|
-
@unquoted = /[^#{
|
104
|
+
@unquoted = /[^#{xsep}#{@cr}#{@lf}][^#{@quote}#{@cr}#{@lf}]*/o
|
104
105
|
@leadzero = /\A0\d*\z/
|
105
106
|
|
106
107
|
yield self if block_given?
|
@@ -252,3 +253,42 @@ class Censive < StringScanner
|
|
252
253
|
abort "\n#{File.basename($0)}: #{msg} at character #{pos} near '#{string[pos-4,7]}'"
|
253
254
|
end
|
254
255
|
end
|
256
|
+
|
257
|
+
if __FILE__ == $0
|
258
|
+
str = DATA.gets("\n\n").chomp
|
259
|
+
# str = File.read(ARGV.first || "lc-2023.csv")
|
260
|
+
# str = File.open("KEN_ALL.CSV", "r:cp932").read
|
261
|
+
|
262
|
+
# require "stringio"
|
263
|
+
# csv = Censive.new(str, excel: true, relax: true)
|
264
|
+
# out = "" # StringIO.new
|
265
|
+
# csv.export(out: out) # (excel: true) # sep: "|")
|
266
|
+
# puts out # .string
|
267
|
+
|
268
|
+
# csv = Censive.new(str, excel: true, relax: true, out: "")
|
269
|
+
# out = csv.export
|
270
|
+
# puts out.out
|
271
|
+
|
272
|
+
puts Censive.parse(str, excel: true, relax: true).to_csv
|
273
|
+
end
|
274
|
+
|
275
|
+
__END__
|
276
|
+
"AAA "BBB",CCC,"DDD"
|
277
|
+
|
278
|
+
"CHUI, LOK HANG "BENNY",224325325610,="001453","Hemoglobin A1c",=""
|
279
|
+
"Don",="007",10,"Ed"
|
280
|
+
Name,Age,,,Shoe,,,
|
281
|
+
"Alice",27,5
|
282
|
+
Bob,33,10 1/2
|
283
|
+
Charlie or "Chuck",=B2 + B3,9
|
284
|
+
Subtotal,=sum(B2:B5),="01234"
|
285
|
+
A,B,C,D
|
286
|
+
A,B,"C",D
|
287
|
+
A,B,C",D
|
288
|
+
A,B,"C",D
|
289
|
+
08/27/2022,="73859443",="04043260",,"Crossover @ Mathilda","CHO, JOELLE "JOJO"",08/19/2022
|
290
|
+
123,
|
291
|
+
123,"CHO, JOELLE "JOJO"",456
|
292
|
+
123,"CHO, JOELLE ""JOJO""",456
|
293
|
+
=,=x,x=,="x",="","","=",123,0123,="123",="0123"
|
294
|
+
,=x,x=,x,,,,,,=,,123,="0123",123,,="0123"
|
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.27'
|
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-03-
|
11
|
+
date: 2023-03-20 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
|