censive 0.21 → 0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dffdaf597e038881e378eb30acb7c44cde08de1f9e40e2180076eaa11356c68
4
- data.tar.gz: f9d7f77ac597a5d5a86fc1adcad430802ab20bd306bf5856f1191f57ff22f872
3
+ metadata.gz: 5a787932ff608f1df361b6faca419ce69eac2cafe853aa7c16155c5f2ace4621
4
+ data.tar.gz: 1818249a3e778223297adaff85216c6497d2f802c25e77664ec1525e51dc9d2d
5
5
  SHA512:
6
- metadata.gz: a0187489ebac8a9011f0f77dc9d52ca821ab080271f3eca6a1a40409b587534a9f4608d1f3b65a0253e587c242d01465e3cd773377f8d00b2fbd1723db4b5650
7
- data.tar.gz: 94f2e7a204d8b40e058f41d193add0002d169d5d244e81c6895e465de159c6a953f09e313689891f7d12c05bead3baa41ad6fd525a8e297143758553e39ef1ba
6
+ metadata.gz: 9ecf977a34e9cd5f86fdc8843aa64b2212bcf608a30eef579593e5af5d3c9ab00164d0dac1030738898ccfe4b541366d711ac8a029b2f907071c113543d10003
7
+ data.tar.gz: 90780a1b7ca9be28eb7e83392ba00f0d4a7374c05b91845605cf9f8c64d58d5e187d468de96dfabe2126f331944ca94b4d4f5af286750c054db13731bfe8830d
data/censive.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "censive"
3
- s.version = "0.21"
3
+ s.version = "0.23"
4
4
  s.author = "Steve Shreeve"
5
5
  s.email = "steve.shreeve@gmail.com"
6
6
  s.summary =
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: Feb 14, 2023
7
+ # Date: Feb 17, 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
- attr :encoding, :out
31
+ attr :encoding, :out, :rows
32
32
 
33
33
  def self.parse(...)
34
34
  new(...).parse
@@ -46,11 +46,11 @@ class Censive < StringScanner
46
46
  drop: false , # drop trailing empty columns?
47
47
  encoding: nil , # character encoding
48
48
  excel: false , # literals ="01" formulas =A1 + B2 http://bit.ly/3Y7jIvc
49
- mode: :compact, # export mode: compact or full
49
+ mode: :compact, # output mode: compact or full
50
50
  out: nil , # output stream, needs to respond to <<
51
51
  quote: '"' , # quote character
52
52
  relax: false , # relax quote parsing so ,"Fo"o, => ,"Fo""o",
53
- rowsep: "\n" , # row separator for export
53
+ rowsep: "\n" , # row separator for output
54
54
  sep: "," , # column separator character
55
55
  strip: false , # strip columns when reading
56
56
  **opts # grab bag
@@ -71,7 +71,7 @@ class Censive < StringScanner
71
71
  @encoding = str.encoding
72
72
  @excel = excel
73
73
  @mode = mode
74
- @out = out || $stdout
74
+ @out = out || ""
75
75
  @relax = relax
76
76
  @strip = strip
77
77
 
@@ -121,7 +121,7 @@ class Censive < StringScanner
121
121
  @cols = count if count > @cols
122
122
  @cells += count
123
123
  end
124
- @rows
124
+ self
125
125
  end
126
126
 
127
127
  def next_row
@@ -179,10 +179,10 @@ class Censive < StringScanner
179
179
  @rows.each {|row| yield row }
180
180
  end
181
181
 
182
- def export(**opts)
183
- out = opts.empty? ? self : self.class.writer(**opts)
184
- each {|row| out << row }
185
- out.out
182
+ def to_csv(**opts)
183
+ dest = opts.empty? ? self : self.class.writer(**opts)
184
+ each {|row| dest << row }
185
+ dest.out
186
186
  end
187
187
 
188
188
  # ==[ Helpers ]==
@@ -259,7 +259,11 @@ if __FILE__ == $0
259
259
  # csv.export(out: out) # (excel: true) # sep: "|")
260
260
  # puts out # .string
261
261
 
262
- puts Censive.new(str, excel: true, relax: true, out: "").export
262
+ # csv = Censive.new(str, excel: true, relax: true, out: "")
263
+ # out = csv.export
264
+ # puts out.out
265
+
266
+ Censive.parse(str, excel: true, relax: true).to_csv
263
267
  end
264
268
 
265
269
  __END__
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.21'
4
+ version: '0.23'
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-02-14 00:00:00.000000000 Z
11
+ date: 2023-02-17 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
@@ -19,7 +19,6 @@ files:
19
19
  - LICENSE
20
20
  - README.md
21
21
  - censive.gemspec
22
- - diagram/NFA to Regex.pdf
23
22
  - diagram/censive@ce9d51d.png
24
23
  - diagram/csv-ragel.dot
25
24
  - diagram/csv.dot
@@ -29,9 +28,6 @@ files:
29
28
  - diagram/diagram.dot
30
29
  - diagram/diagram.rl
31
30
  - lib/censive.rb
32
- - lib/test-censive.rb
33
- - lib/test-csv.rb
34
- - test/a-uses-tabs-and-single-quotes-and-no-trailing-newline.tsv
35
31
  homepage: https://github.com/shreeve/censive
36
32
  licenses:
37
33
  - MIT
Binary file
data/lib/test-censive.rb DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "./censive"
4
- require "digest/md5"
5
-
6
- path = ARGV[0] || "KEN_ALL.CSV"
7
- mode = path =~ /^ken/i ? "r:cp932" : "r"
8
-
9
- data = File.open(path, mode).read
10
- rows = Censive.parse(data)
11
-
12
- puts "%s %s (%d size)" % [Digest::MD5.hexdigest(rows.join), path, File.stat(path).size], ""
data/lib/test-csv.rb DELETED
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "csv"
4
- require "digest/md5"
5
-
6
- path = ARGV[0] || "KEN_ALL.CSV"
7
- mode = path =~ /^ken/i ? "r:cp932" : "r"
8
-
9
- data = File.open(path, mode).read
10
- rows = CSV.parse(data)
11
-
12
- puts "%s %s (%d size)" % [Digest::MD5.hexdigest(rows.join), path, File.stat(path).size], ""
@@ -1,3 +0,0 @@
1
- age name
2
- 5 'Mike the ''man!'''
3
- 10 Tommy