censive 1.0.3 → 1.0.5
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 +20 -13
- 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: a6f156186b0612f198563d23cd09fa0cf65d823a92b031bd71a3e22335163b73
|
4
|
+
data.tar.gz: 6ac6ba05c9ee8cb52d1a3c5573dde803144651c7b4a2f3af9d83596d7365bf1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a078837538b6693a92586ebc997e0c7564952509991997215f7e0994d5ebaf29fdde4732feb72a2f418c4d2927115f23e1a7948e9f98a071438bff4c7fa8d255
|
7
|
+
data.tar.gz: 3c28503ad4dc72fbcc0140d61e5d94d6ae44d9deb70842b40bd23406438f7de6b3a2557a39271f463ed1acf93f968e5543b8481d2b02b458a04a3389fa7f6e1f
|
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:
|
7
|
+
# Date: June 16, 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
|
@@ -29,7 +29,7 @@ require "stringio"
|
|
29
29
|
require "strscan"
|
30
30
|
|
31
31
|
class Censive < StringScanner
|
32
|
-
VERSION="1.0.
|
32
|
+
VERSION="1.0.5"
|
33
33
|
|
34
34
|
attr :encoding, :out, :rows
|
35
35
|
|
@@ -39,9 +39,16 @@ class Censive < StringScanner
|
|
39
39
|
|
40
40
|
def self.writer(obj=nil, **opts, &code)
|
41
41
|
case obj
|
42
|
-
when String
|
43
|
-
|
44
|
-
|
42
|
+
when String
|
43
|
+
if block_given?
|
44
|
+
File.open(obj, "w") {|io| new(out: io, **opts, &code) }
|
45
|
+
else
|
46
|
+
new(out: File.open(obj, "w"), **opts)
|
47
|
+
end
|
48
|
+
when StringIO, IO, nil
|
49
|
+
new(out: obj, **opts, &code)
|
50
|
+
else
|
51
|
+
abort "#{File.basename($0)}: invalid #{obj.class} object in writer"
|
45
52
|
end
|
46
53
|
end
|
47
54
|
|
@@ -95,14 +102,14 @@ class Censive < StringScanner
|
|
95
102
|
|
96
103
|
# regexes
|
97
104
|
xsep = Regexp.escape(@sep) # may need to be escaped
|
98
|
-
@eoc = /(?=#{"\\" + xsep}|#{@cr}|#{@lf}|\z)/
|
99
|
-
@eol = /#{@cr}#{@lf}?|#{@lf}/
|
100
|
-
@escapes = /(#{@quote})|#{xsep}|#{@cr}|#{@lf}/
|
101
|
-
@quotable = /#{xsep}|#{@cr}|#{@lf}/
|
102
|
-
@quotes = /#{@quote}/
|
103
|
-
@seps = /#{xsep}+/
|
104
|
-
@quoted = @excel ? /(?:=)?#{@quote}/
|
105
|
-
@unquoted = /[^#{xsep}#{@cr}#{@lf}][^#{@quote}#{@cr}#{@lf}]*/
|
105
|
+
@eoc = /(?=#{"\\" + xsep}|#{@cr}|#{@lf}|\z)/ # end of cell
|
106
|
+
@eol = /#{@cr}#{@lf}?|#{@lf}/ # end of line
|
107
|
+
@escapes = /(#{@quote})|#{xsep}|#{@cr}|#{@lf}/
|
108
|
+
@quotable = /#{xsep}|#{@cr}|#{@lf}/
|
109
|
+
@quotes = /#{@quote}/
|
110
|
+
@seps = /#{xsep}+/
|
111
|
+
@quoted = @excel ? /(?:=)?#{@quote}/ : @quote
|
112
|
+
@unquoted = /[^#{xsep}#{@cr}#{@lf}][^#{@quote}#{@cr}#{@lf}]*/
|
106
113
|
@leadzero = /\A0\d*\z/
|
107
114
|
|
108
115
|
yield self if block_given?
|
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: 1.0.
|
4
|
+
version: 1.0.5
|
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-06-
|
11
|
+
date: 2023-06-27 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
|