censive 0.29 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/censive.rb +42 -3
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3db4c7bfa5df5911b7ec460329f59b1dc858881fcfc65e7bab98800861c40b5b
|
|
4
|
+
data.tar.gz: 2f0e4b3ec85aab97c5b9c1436513a0fa4cafb0395f6b02abe6275346ab684bc7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dcc066cfd497a52a2481137233c40af86048d41889ce01d08d03ddf21a79e29e1e0236bc2fa4a9aeda35ef03d8f24061e5e4978a047f8a8ab9715bd0e902a0af
|
|
7
|
+
data.tar.gz: 3a3bbbbfb2fc787dc1b58c1f295fa25d0d4a1060310d457230aa1b3e4b675a5539c3b91eedf384edef1abf0c3b9ff58e1d6c191571af8f58034edc503266f7f8
|
data/lib/censive.rb
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
require "strscan"
|
|
29
29
|
|
|
30
30
|
class Censive < StringScanner
|
|
31
|
-
VERSION="0.
|
|
31
|
+
VERSION="1.0.1"
|
|
32
32
|
|
|
33
33
|
attr :encoding, :out, :rows
|
|
34
34
|
|
|
@@ -199,7 +199,7 @@ class Censive < StringScanner
|
|
|
199
199
|
|
|
200
200
|
# returns 2 (must be quoted and escaped), 1 (must be quoted), 0 (neither)
|
|
201
201
|
def grok(str)
|
|
202
|
-
if idx = str
|
|
202
|
+
if idx = str&.index(@escapes)
|
|
203
203
|
$1 ? 2 : str.index(@quote, idx) ? 2 : 1
|
|
204
204
|
else
|
|
205
205
|
0
|
|
@@ -220,7 +220,7 @@ class Censive < StringScanner
|
|
|
220
220
|
row
|
|
221
221
|
when 1
|
|
222
222
|
row.map do |col|
|
|
223
|
-
col
|
|
223
|
+
col&.match?(@quotable) ? "#{q}#{col}#{q}" : col
|
|
224
224
|
end
|
|
225
225
|
else
|
|
226
226
|
row.map do |col|
|
|
@@ -257,3 +257,42 @@ class Censive < StringScanner
|
|
|
257
257
|
abort "\n#{File.basename($0)}: #{msg} at character #{pos} near '#{string[pos-4,7]}'"
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
|
+
|
|
261
|
+
if __FILE__ == $0
|
|
262
|
+
str = DATA.gets("\n\n").chomp
|
|
263
|
+
# str = File.read(ARGV.first || "lc-2023.csv")
|
|
264
|
+
# str = File.open("KEN_ALL.CSV", "r:cp932").read
|
|
265
|
+
|
|
266
|
+
# require "stringio"
|
|
267
|
+
# csv = Censive.new(str, excel: true, relax: true)
|
|
268
|
+
# out = "" # StringIO.new
|
|
269
|
+
# csv.export(out: out) # (excel: true) # sep: "|")
|
|
270
|
+
# puts out # .string
|
|
271
|
+
|
|
272
|
+
# csv = Censive.new(str, excel: true, relax: true, out: "")
|
|
273
|
+
# out = csv.export
|
|
274
|
+
# puts out.out
|
|
275
|
+
|
|
276
|
+
puts Censive.parse(str, excel: true, relax: true).to_csv
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
__END__
|
|
280
|
+
"AAA "BBB",CCC,"DDD"
|
|
281
|
+
|
|
282
|
+
"CHUI, LOK HANG "BENNY",224325325610,="001453","Hemoglobin A1c",=""
|
|
283
|
+
"Don",="007",10,"Ed"
|
|
284
|
+
Name,Age,,,Shoe,,,
|
|
285
|
+
"Alice",27,5
|
|
286
|
+
Bob,33,10 1/2
|
|
287
|
+
Charlie or "Chuck",=B2 + B3,9
|
|
288
|
+
Subtotal,=sum(B2:B5),="01234"
|
|
289
|
+
A,B,C,D
|
|
290
|
+
A,B,"C",D
|
|
291
|
+
A,B,C",D
|
|
292
|
+
A,B,"C",D
|
|
293
|
+
08/27/2022,="73859443",="04043260",,"Crossover @ Mathilda","CHO, JOELLE "JOJO"",08/19/2022
|
|
294
|
+
123,
|
|
295
|
+
123,"CHO, JOELLE "JOJO"",456
|
|
296
|
+
123,"CHO, JOELLE ""JOJO""",456
|
|
297
|
+
=,=x,x=,="x",="","","=",123,0123,="123",="0123"
|
|
298
|
+
,=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:
|
|
4
|
+
version: 1.0.1
|
|
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-
|
|
11
|
+
date: 2023-04-10 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
|
|
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
48
|
version: '0'
|
|
49
49
|
requirements: []
|
|
50
|
-
rubygems_version: 3.4.
|
|
50
|
+
rubygems_version: 3.4.10
|
|
51
51
|
signing_key:
|
|
52
52
|
specification_version: 4
|
|
53
53
|
summary: A quick and lightweight CSV handling library for Ruby
|