censive 0.28 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/censive.rb +11 -7
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9d7a9c43e8371994aba6118bc34e34eeb250a3f289e4a3dfe724cb6f9e42cb1
4
- data.tar.gz: 84bde447c2e0de60e03a17afc3d266f4018ce7aad5dd0f690d3d52438e0fd343
3
+ metadata.gz: 246be731b3c88020be3432707b0fb66b8624bc6ebd18b54dae56d813defc7ae9
4
+ data.tar.gz: 13ee5d519f07b82c410a1afcdeaf01678be8e43de894b00e7d6a1bab09e9cf92
5
5
  SHA512:
6
- metadata.gz: 5eeb09213826f6cd2821d83c0559034163ac701a2cbd3ef190df3dbfde31167d529f51e30363e585b65fc9a7dd29259b14d2957e7ff2f299878de24e3710e2ce
7
- data.tar.gz: 4e54a08d30e433234caa04d94bfcbfef2bb2b9f2b36a4a2f6248bab77dd5fbf410f2fef69ab43c7b2c76a8e79d9d50780d55396aabc9c8dab876db820370e9e1
6
+ metadata.gz: a36473da2784c22dd99a4a414388699942d2bcfcbe87d3883f4efa4234922d99db4aa359102f9f56ae2d94d162d7391ca8caffdbaf3cf550f8a50a00b7b19fc5
7
+ data.tar.gz: 27a07ae5bbcc85c5b48116b935cdd62d39d1b34bf66abf31ab255ab7562ee0fdd1ad44a42990387ee0057a5423175e00117de98c9484564b65e4baea2fda415a
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 20, 2023
7
+ # Date: Mar 22, 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
@@ -28,7 +28,7 @@
28
28
  require "strscan"
29
29
 
30
30
  class Censive < StringScanner
31
- VERSION="0.28"
31
+ VERSION="1.0.0"
32
32
 
33
33
  attr :encoding, :out, :rows
34
34
 
@@ -185,10 +185,14 @@ class Censive < StringScanner
185
185
  @rows.each {|row| yield row }
186
186
  end
187
187
 
188
- def to_csv(**opts)
189
- dest = opts.empty? ? self : self.class.writer(**opts)
190
- each {|row| dest << row }
191
- dest.out
188
+ def to_csv(*args, **opts, &code)
189
+ if args.empty? && opts.empty?
190
+ block_given? ? each(&code) : each {|row| @out << row }
191
+ elsif block_given?
192
+ Censive.writer(*args, **opts, &code)
193
+ else
194
+ Censive.writer(*args, **opts) {|csv| each {|row| csv << row }}
195
+ end
192
196
  end
193
197
 
194
198
  # ==[ Helpers ]==
@@ -216,7 +220,7 @@ class Censive < StringScanner
216
220
  row
217
221
  when 1
218
222
  row.map do |col|
219
- col.match?(@quotable) ? "#{q}#{col}#{q}" : col
223
+ col&.match?(@quotable) ? "#{q}#{col}#{q}" : col
220
224
  end
221
225
  else
222
226
  row.map do |col|
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.28'
4
+ version: 1.0.0
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-20 00:00:00.000000000 Z
11
+ date: 2023-03-30 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.8
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