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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/censive.rb +20 -13
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b3192a24670593887dbf1e955c2db44c912248b4eef81c2f89d411190ff7a7c
4
- data.tar.gz: f95e5e02f4930f8478fa0bae557e13f72d93637e7bb1d4458a6fa46e022f76cb
3
+ metadata.gz: a6f156186b0612f198563d23cd09fa0cf65d823a92b031bd71a3e22335163b73
4
+ data.tar.gz: 6ac6ba05c9ee8cb52d1a3c5573dde803144651c7b4a2f3af9d83596d7365bf1c
5
5
  SHA512:
6
- metadata.gz: 38405a381813ba7d8f575b654c1593f3e0cf7d3869258f8956c5631ac8887e78a292bb7838773af9ea6b42590fd28d4aa4f2b654d4caa5c60f24470bd7df3c4e
7
- data.tar.gz: 85168aaaf282d7a273068c906cd98347f91ada39daa8e9d7967dce23796e9ab632ea62d1be9ad0ade55dd01de9865eeff1afdccc571199cb23ff6b2ba976629d
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: Mar 22, 2023
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.3"
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 then File.open(obj, "w") {|io| new(out: io, **opts, &code) }
43
- when StringIO,IO,nil then new(out: obj, **opts, &code)
44
- else abort "#{File.basename($0)}: invalid #{obj.class} object in writer"
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)/o # end of cell
99
- @eol = /#{@cr}#{@lf}?|#{@lf}/o # end of line
100
- @escapes = /(#{@quote})|#{xsep}|#{@cr}|#{@lf}/o
101
- @quotable = /#{xsep}|#{@cr}|#{@lf}/o
102
- @quotes = /#{@quote}/o
103
- @seps = /#{xsep}+/o
104
- @quoted = @excel ? /(?:=)?#{@quote}/o : @quote
105
- @unquoted = /[^#{xsep}#{@cr}#{@lf}][^#{@quote}#{@cr}#{@lf}]*/o
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.3
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-15 00:00:00.000000000 Z
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