censive 0.23 → 0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/censive.gemspec +1 -1
  3. data/lib/censive.rb +8 -37
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a787932ff608f1df361b6faca419ce69eac2cafe853aa7c16155c5f2ace4621
4
- data.tar.gz: 1818249a3e778223297adaff85216c6497d2f802c25e77664ec1525e51dc9d2d
3
+ metadata.gz: 576378807981d5da8807494a94c45c7a9c42939f216b579daa97b39bfd179b28
4
+ data.tar.gz: 325e720a55384d7ecee7059b3889e2c401f0bed74bf3a212b44533113017a3a1
5
5
  SHA512:
6
- metadata.gz: 9ecf977a34e9cd5f86fdc8843aa64b2212bcf608a30eef579593e5af5d3c9ab00164d0dac1030738898ccfe4b541366d711ac8a029b2f907071c113543d10003
7
- data.tar.gz: 90780a1b7ca9be28eb7e83392ba00f0d4a7374c05b91845605cf9f8c64d58d5e187d468de96dfabe2126f331944ca94b4d4f5af286750c054db13731bfe8830d
6
+ metadata.gz: 5975a7104ed337ce034e76d322cc6096714cbfd3807261ec127d5c8ed78f438e618d1d72ea1d8e7fa058e561690c63cf4662967f6d5311c100169144e974225f
7
+ data.tar.gz: 359d426bd92041250647aa85c17262b1a6356c49147236c3b6ab86df16c56e87708b09839c74970ccafa17121d80ee764b80824b5723ea3817447ba43d514ae9
data/censive.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "censive"
3
- s.version = "0.23"
3
+ s.version = `grep '^VERSION' lib/censive.rb | cut -f 2 -d '"'`
4
4
  s.author = "Steve Shreeve"
5
5
  s.email = "steve.shreeve@gmail.com"
6
6
  s.summary =
data/lib/censive.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ VERSION="0.25"
4
+
3
5
  # ============================================================================
4
6
  # censive - A quick and lightweight CSV handling library for Ruby
5
7
  #
@@ -36,7 +38,7 @@ class Censive < StringScanner
36
38
 
37
39
  def self.writer(obj=nil, **opts, &code)
38
40
  case obj
39
- when String then File.open(obj, "w") {|io| yield new(out: io, **opts, &code) }
41
+ when String then File.open(obj, "w") {|io| new(out: io, **opts, &code) }
40
42
  when IO,nil then new(out: obj, **opts, &code)
41
43
  else abort "#{File.basename($0)}: invalid #{obj.class} object in writer"
42
44
  end
@@ -71,7 +73,7 @@ class Censive < StringScanner
71
73
  @encoding = str.encoding
72
74
  @excel = excel
73
75
  @mode = mode
74
- @out = out || ""
76
+ @out = out || $stdout
75
77
  @relax = relax
76
78
  @strip = strip
77
79
 
@@ -100,6 +102,8 @@ class Censive < StringScanner
100
102
  @quoted = @excel ? /(?:=)?#{@quote}/o : @quote
101
103
  @unquoted = /[^#{@sep}#{@cr}#{@lf}][^#{@quote}#{@cr}#{@lf}]*/o
102
104
  @leadzero = /\A0\d*\z/
105
+
106
+ yield self if block_given?
103
107
  end
104
108
 
105
109
  def reset(str=nil)
@@ -153,6 +157,7 @@ class Censive < StringScanner
153
157
  scan(@eoc) and break
154
158
  @relax or bomb "invalid character after quote"
155
159
  token << @quote + (scan_until(@quotes) or bomb "bad inline quote")
160
+ scan(@eoc) and break
156
161
  end
157
162
  scan(@sep)
158
163
  @strip ? token.strip : token
@@ -190,7 +195,7 @@ class Censive < StringScanner
190
195
  # returns 2 (must be quoted and escaped), 1 (must be quoted), 0 (neither)
191
196
  def grok(str)
192
197
  if idx = str.index(@escapes)
193
- $1 ? 2 : str.index(@quotes, idx) ? 2 : 1
198
+ $1 ? 2 : str.index(@quote, idx) ? 2 : 1
194
199
  else
195
200
  0
196
201
  end
@@ -247,37 +252,3 @@ class Censive < StringScanner
247
252
  abort "\n#{File.basename($0)}: #{msg} at character #{pos} near '#{string[pos-4,7]}'"
248
253
  end
249
254
  end
250
-
251
- if __FILE__ == $0
252
- str = DATA.gets("\n\n").chomp
253
- # str = File.read(ARGV.first || "lc-2023.csv")
254
- # str = File.open("KEN_ALL.CSV", "r:cp932").read
255
-
256
- # require "stringio"
257
- # csv = Censive.new(str, excel: true, relax: true)
258
- # out = "" # StringIO.new
259
- # csv.export(out: out) # (excel: true) # sep: "|")
260
- # puts out # .string
261
-
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
267
- end
268
-
269
- __END__
270
- "Don",="007",10,"Ed"
271
- Name,Age,,,Shoe,,,
272
- "Alice",27,5
273
- Bob,33,10 1/2
274
- Charlie or "Chuck",=B2 + B3,9
275
- Subtotal,=sum(B2:B5),="01234"
276
- A,B,C,D
277
- A,B,"C",D
278
- A,B,C",D
279
- A,B,"C",D
280
- 123,"CHO, JOELLE "JOJO"",456
281
- 123,"CHO, JOELLE ""JOJO""",456
282
- =,=x,x=,="x",="","","=",123,0123,="123",="0123"
283
- ,=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.23'
4
+ version: '0.25'
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-17 00:00:00.000000000 Z
11
+ date: 2023-03-15 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.6
50
+ rubygems_version: 3.4.8
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: A quick and lightweight CSV handling library for Ruby