censive 0.22 → 0.24

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: 5f9bbebb5cd4aba5b0d22ec2f87e129a47292fc999ada61284ea53e5458c1d42
4
- data.tar.gz: 9db7f322767ab0fe4275e2c40c0e466dd3654b1180aed55a4aa8826bddee3f78
3
+ metadata.gz: 76c05b90f6a522a328f86d7d142ed150b33c487e74619707e10f40453c7e9079
4
+ data.tar.gz: 1e5a93d293ad708b323e20e1323926f2bf70e219ffc502e8fc87025be7be23b6
5
5
  SHA512:
6
- metadata.gz: a6b3eda844db32d8f50a9972eff3a2c1d690dc8bdcc0eb0276df6dea722d6a45790236e2b0dfaceb17555e153ce44f54c7b18df961babea70ac764ca03aeffa5
7
- data.tar.gz: f3c153d47ddc3e2e27be33407d0ca9159776590d42b79e4cfa41c932b9cde3daa3dfdc68de238b3e34a243bc6aff4cfc34df7cc0a1b1aafc27cd0a77c185a8fa
6
+ metadata.gz: e56b1a6a0f943d962ff8c240625a8354283fcbccd1a640cd66054873e1803779ddb36e128841590e8a8aa0022694e1e22a4fa25b6f88eba7056dc68b838262fb
7
+ data.tar.gz: 41ddfb9d77a686bef546836d0a110b9603ac7e4f205b7d9760ed37203d23f32f6ba9d2cc5fcb9f8996713fbcdec8fcb924298b1052c1ecc5e9f6442deed3078f
data/censive.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "censive"
3
- s.version = "0.22"
3
+ s.version = "0.24"
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
@@ -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
@@ -153,6 +153,7 @@ class Censive < StringScanner
153
153
  scan(@eoc) and break
154
154
  @relax or bomb "invalid character after quote"
155
155
  token << @quote + (scan_until(@quotes) or bomb "bad inline quote")
156
+ scan(@eoc) and break
156
157
  end
157
158
  scan(@sep)
158
159
  @strip ? token.strip : token
@@ -179,10 +180,10 @@ class Censive < StringScanner
179
180
  @rows.each {|row| yield row }
180
181
  end
181
182
 
182
- def export(**opts)
183
+ def to_csv(**opts)
183
184
  dest = opts.empty? ? self : self.class.writer(**opts)
184
185
  each {|row| dest << row }
185
- dest
186
+ dest.out
186
187
  end
187
188
 
188
189
  # ==[ Helpers ]==
@@ -190,7 +191,7 @@ class Censive < StringScanner
190
191
  # returns 2 (must be quoted and escaped), 1 (must be quoted), 0 (neither)
191
192
  def grok(str)
192
193
  if idx = str.index(@escapes)
193
- $1 ? 2 : str.index(@quotes, idx) ? 2 : 1
194
+ $1 ? 2 : str.index(@quote, idx) ? 2 : 1
194
195
  else
195
196
  0
196
197
  end
@@ -259,12 +260,17 @@ if __FILE__ == $0
259
260
  # csv.export(out: out) # (excel: true) # sep: "|")
260
261
  # puts out # .string
261
262
 
262
- csv = Censive.new(str, excel: true, relax: true, out: "")
263
- out = csv.export
264
- puts out.out
263
+ # csv = Censive.new(str, excel: true, relax: true, out: "")
264
+ # out = csv.export
265
+ # puts out.out
266
+
267
+ puts Censive.parse(str, excel: true, relax: true).to_csv
265
268
  end
266
269
 
267
270
  __END__
271
+ "AAA "BBB",CCC,"DDD"
272
+
273
+ "CHUI, LOK HANG "BENNY",224325325610,="001453","Hemoglobin A1c",=""
268
274
  "Don",="007",10,"Ed"
269
275
  Name,Age,,,Shoe,,,
270
276
  "Alice",27,5
@@ -275,6 +281,8 @@ A,B,C,D
275
281
  A,B,"C",D
276
282
  A,B,C",D
277
283
  A,B,"C",D
284
+ 08/27/2022,="73859443",="04043260",,"Crossover @ Mathilda","CHO, JOELLE "JOJO"",08/19/2022
285
+ 123,
278
286
  123,"CHO, JOELLE "JOJO"",456
279
287
  123,"CHO, JOELLE ""JOJO""",456
280
288
  =,=x,x=,="x",="","","=",123,0123,="123",="0123"
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.22'
4
+ version: '0.24'
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