censive 0.17 → 0.19

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 -3
  3. data/lib/censive.rb +28 -23
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88b2018e7ca027d44e36061d9cdc983b56e510632bc125ca632b85fbdc15999b
4
- data.tar.gz: 3ec807310f681afdec72505269c23a6a6d9b0262134dbbcd0b16cc6406c9fc50
3
+ metadata.gz: ff272ee20f4d6b15b65622fa444b494cd58fd01c651b6b6e3685539c0633299d
4
+ data.tar.gz: e7a5890bf19b674fa63c8268c8f7a6895f9811984ade1368823ee273dc30aa01
5
5
  SHA512:
6
- metadata.gz: b0110e0ff7dc4f902ede1c7086e6431d3671f1c5886c6947e493bc85ad48bda3232d3604b269703ad3bfdb0d7b1d180cb55ea12fdf06bcc9729a1d67d2cd85a7
7
- data.tar.gz: 90dbb68deed9124a723eba91574f46829bf870277f874433ad34fc63dfb4376a8bda243b9fdbb86fbfee90e18bd169e4b8cc97fa6f6f3dac43bbc2125dac877d
6
+ metadata.gz: 3156bc0abdf0b59d4f95be11e396f18421a17bf21b0e0cdc4c6e9b63f864ac9bb75a5db6480df07fba82633a11ce4b43dd24e917352f15f2db27de517a08f314
7
+ data.tar.gz: cc688477d6b85152241fd6619cd58441c4805f1cef762a819de2e7a69cb4a5ba4f2b2a688a9e32590dbe32ef4c0fdbd796d8ffe2607ae635b192da04054ad571
data/censive.gemspec CHANGED
@@ -1,8 +1,6 @@
1
- # encoding: utf-8
2
-
3
1
  Gem::Specification.new do |s|
4
2
  s.name = "censive"
5
- s.version = "0.17"
3
+ s.version = "0.19"
6
4
  s.author = "Steve Shreeve"
7
5
  s.email = "steve.shreeve@gmail.com"
8
6
  s.summary =
data/lib/censive.rb CHANGED
@@ -22,6 +22,9 @@
22
22
  require "strscan"
23
23
 
24
24
  class Censive < StringScanner
25
+ def self.parse(...)
26
+ new(...).parse
27
+ end
25
28
 
26
29
  def self.writer(obj=nil, **opts, &code)
27
30
  case obj
@@ -31,34 +34,36 @@ class Censive < StringScanner
31
34
  end
32
35
  end
33
36
 
34
- def initialize(str=nil,
35
- drop: false , # drop trailing empty fields?
36
- excel: false , # literals ="01" formulas =A1 + B2 http://bit.ly/3Y7jIvc
37
- mode: :compact, # export mode: compact or full
38
- out: $stdout , # output stream, needs to respond to <<
39
- quote: '"' , # quote character
40
- relax: false , # relax quote parsing so ,"Fo"o, => ,"Fo""o",
41
- rowsep: "\n" , # row separator for export
42
- sep: "," , # column separator character
43
- strip: false , # strip fields when reading
37
+ def initialize(str="",
38
+ drop: false , # drop trailing empty fields?
39
+ encoding: "utf-8" , # character encoding
40
+ excel: false , # literals ="01" formulas =A1 + B2 http://bit.ly/3Y7jIvc
41
+ mode: :compact, # export mode: compact or full
42
+ out: $stdout , # output stream, needs to respond to <<
43
+ quote: '"' , # quote character
44
+ relax: false , # relax quote parsing so ,"Fo"o, => ,"Fo""o",
45
+ rowsep: "\n" , # row separator for export
46
+ sep: "," , # column separator character
47
+ strip: false , # strip fields when reading
44
48
  **opts # grab bag
45
49
  )
46
- str = File.read(str) if str =~ /\A.{,100}\z/
47
- super(str || "")
50
+ # data source
51
+ str = File.open(str, "r:#{encoding}").read if !str[100] && File.readable?(str)
52
+ super(str)
48
53
  reset
49
54
 
50
55
  # options
51
- @drop = drop
52
- @excel = excel
53
- @mode = mode
54
- @out = out
55
- @quote = quote
56
- @relax = relax
57
- @rowsep = rowsep
58
- @sep = sep
59
- @strip = strip
60
-
61
- # determined
56
+ @drop = drop
57
+ @excel = excel
58
+ @mode = mode
59
+ @out = out
60
+ @quote = quote
61
+ @relax = relax
62
+ @rowsep = rowsep
63
+ @sep = sep
64
+ @strip = strip
65
+
66
+ # definitions
62
67
  @cr = "\r"
63
68
  @lf = "\n"
64
69
  @es = ""
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: censive
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.17'
4
+ version: '0.19'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve