censive 0.11 → 0.13
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 +13 -7
- 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: f3d6b5bd88adf5c40972cd5a978b49e57a7a8724780eeaaf80b0cb749323dc1d
|
4
|
+
data.tar.gz: c24b0efa60901ca6d8de7e8314a3b137c981601b866d837123a96722acf826db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3584864597a1631179212563d29ad188a55c2ed90dd1d36c6464e641ee6b5a85c01437516cdf2865c39e9f4f9bfc96605ae318ca456d722afc544e31d87e1801
|
7
|
+
data.tar.gz: a7c59e427ca7014e0207dc8c3bb8eb1647c41f9193de021dc4a0ee98b913cfa54105f5bbf5301c2ec852feace0ed7d69622008acc2c09697b5ab1e9560fd89d3
|
data/censive.gemspec
CHANGED
data/lib/censive.rb
CHANGED
@@ -22,14 +22,14 @@
|
|
22
22
|
# 3. Support CSV headers in first row
|
23
23
|
# ============================================================================
|
24
24
|
|
25
|
-
require
|
26
|
-
require
|
25
|
+
require "bundler/setup"
|
26
|
+
require "strscan"
|
27
27
|
|
28
28
|
class Censive < StringScanner
|
29
29
|
|
30
30
|
def self.writer(obj=nil, **opts, &code)
|
31
31
|
case obj
|
32
|
-
when String then File.open(
|
32
|
+
when String then File.open(obj, "w") {|io| yield new(out: io, **opts, &code) }
|
33
33
|
when IO,nil then new(out: obj, **opts, &code)
|
34
34
|
else abort "#{File.basename($0)}: invalid #{obj.class} object in writer"
|
35
35
|
end
|
@@ -43,10 +43,10 @@ class Censive < StringScanner
|
|
43
43
|
out: nil , # output stream, needs to respond to <<
|
44
44
|
quote: '"' , # quote character
|
45
45
|
relax: false , # relax quote parsing so ,"Fo"o, => ,"Fo""o",
|
46
|
-
sep:
|
46
|
+
sep: "," , # column separator character
|
47
47
|
**opts # grab bag
|
48
48
|
)
|
49
|
-
super(str ||
|
49
|
+
super(str || "")
|
50
50
|
reset
|
51
51
|
|
52
52
|
@drop = drop
|
@@ -143,7 +143,7 @@ class Censive < StringScanner
|
|
143
143
|
|
144
144
|
# returns 2 (must be quoted and escaped), 1 (must be quoted), 0 (neither)
|
145
145
|
def grok(str)
|
146
|
-
if idx = str.index(/(#{@quote})|#{@sep}|#{@cr}|#{@lf}/o) #!# FIXME: regex injection
|
146
|
+
if idx = str.index(/(#{@quote})|#{@sep}|#{@cr}|#{@lf}/o) #!# FIXME: regex injection?
|
147
147
|
$1 ? 2 : str.index(/#{@quote}/o, idx) ? 2 : 1
|
148
148
|
else
|
149
149
|
0
|
@@ -177,7 +177,13 @@ class Censive < StringScanner
|
|
177
177
|
end
|
178
178
|
end
|
179
179
|
when :full
|
180
|
-
|
180
|
+
if @excel
|
181
|
+
row.map do |col|
|
182
|
+
col =~ /\A0\d*\z/ ? "=#{q}#{col}#{q}" : "#{q}#{col.gsub(q, @esc)}#{q}"
|
183
|
+
end
|
184
|
+
else
|
185
|
+
row.map {|col| "#{q}#{col.gsub(q, @esc)}#{q}" }
|
186
|
+
end
|
181
187
|
end.join(s)
|
182
188
|
|
183
189
|
@out << out + @eol
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: censive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.13'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
requirements: []
|
57
|
-
rubygems_version: 3.4.
|
57
|
+
rubygems_version: 3.4.6
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: A quick and lightweight CSV handling library for Ruby
|