csv 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/NEWS.md +377 -0
- data/README.md +1 -0
- data/lib/csv/delete_suffix.rb +18 -0
- data/lib/csv/fields_converter.rb +78 -0
- data/lib/csv/match_p.rb +20 -0
- data/lib/csv/parser.rb +1092 -0
- data/lib/csv/row.rb +6 -6
- data/lib/csv/table.rb +28 -4
- data/lib/csv/version.rb +1 -1
- data/lib/csv/writer.rb +156 -0
- data/lib/csv.rb +330 -632
- metadata +24 -5
- data/news.md +0 -123
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e3a871d4d1958c763228c4b8d702c3cb272017934a37927e87b6ef7a86959bc
|
4
|
+
data.tar.gz: 39effdc25704e1e1f312c55d8461b3f5cce0eac7c2262ba21302783527004aae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83fa32fa7ceccb2a9287e3de846df483ae13088edbc5bb1dcaf9a27b74bbfb7da151334c85c8a146baa325cc4f39dbcc87c32f954ee0fbc41786816ab9a80716
|
7
|
+
data.tar.gz: 2a054323b17fa11a6febecb0060613f5b5bc339e4014fd6d1dd95ebcbb88bb72a85c8a3201d06b02c7cbb5134852838676de7b15525e6a261e1f7d6a7927cfa4
|
data/NEWS.md
ADDED
@@ -0,0 +1,377 @@
|
|
1
|
+
# News
|
2
|
+
|
3
|
+
## 3.1.0 - 2019-04-17
|
4
|
+
|
5
|
+
### Fixes
|
6
|
+
|
7
|
+
* Fixed a backward incompatibility bug that `CSV#eof?` may raises an
|
8
|
+
error.
|
9
|
+
[GitHub#86][Reported by krororo]
|
10
|
+
|
11
|
+
### Thanks
|
12
|
+
|
13
|
+
* krororo
|
14
|
+
|
15
|
+
## 3.0.9 - 2019-04-15
|
16
|
+
|
17
|
+
### Fixes
|
18
|
+
|
19
|
+
* Fixed a test for Windows.
|
20
|
+
|
21
|
+
## 3.0.8 - 2019-04-11
|
22
|
+
|
23
|
+
### Fixes
|
24
|
+
|
25
|
+
* Fixed a bug that `strip: String` doesn't work.
|
26
|
+
|
27
|
+
## 3.0.7 - 2019-04-08
|
28
|
+
|
29
|
+
### Improvements
|
30
|
+
|
31
|
+
* Improve parse performance 1.5x by introducing loose parser.
|
32
|
+
|
33
|
+
### Fixes
|
34
|
+
|
35
|
+
* Fix performance regression in 3.0.5.
|
36
|
+
|
37
|
+
* Fix a bug that `CSV#line` returns wrong value when you
|
38
|
+
use `quote_char: nil`.
|
39
|
+
|
40
|
+
## 3.0.6 - 2019-03-30
|
41
|
+
|
42
|
+
### Improvements
|
43
|
+
|
44
|
+
* `CSV.foreach`: Added support for `mode`.
|
45
|
+
|
46
|
+
## 3.0.5 - 2019-03-24
|
47
|
+
|
48
|
+
### Improvements
|
49
|
+
|
50
|
+
* Added `:liberal_parsing => {backslash_quote: true}` option.
|
51
|
+
[GitHub#74][Patch by 284km]
|
52
|
+
|
53
|
+
* Added `:write_converters` option.
|
54
|
+
[GitHub#73][Patch by Danillo Souza]
|
55
|
+
|
56
|
+
* Added `:write_nil_value` option.
|
57
|
+
|
58
|
+
* Added `:write_empty_value` option.
|
59
|
+
|
60
|
+
* Improved invalid byte line number detection.
|
61
|
+
[GitHub#78][Patch by Alyssa Ross]
|
62
|
+
|
63
|
+
* Added `quote_char: nil` optimization.
|
64
|
+
[GitHub#79][Patch by 284km]
|
65
|
+
|
66
|
+
* Improved error message.
|
67
|
+
[GitHub#81][Patch by Andrés Torres]
|
68
|
+
|
69
|
+
* Improved IO-like implementation for `StringIO` data.
|
70
|
+
[GitHub#80][Patch by Genadi Samokovarov]
|
71
|
+
|
72
|
+
* Added `:strip` option.
|
73
|
+
[GitHub#58]
|
74
|
+
|
75
|
+
### Fixes
|
76
|
+
|
77
|
+
* Fixed a compatibility bug that `CSV#each` doesn't care `CSV#shift`.
|
78
|
+
[GitHub#76][Patch by Alyssa Ross]
|
79
|
+
|
80
|
+
* Fixed a compatibility bug that `CSV#eof?` doesn't care `CSV#each`
|
81
|
+
and `CSV#shift`.
|
82
|
+
[GitHub#77][Reported by Chi Leung]
|
83
|
+
|
84
|
+
* Fixed a compatibility bug that invalid line isn't ignored.
|
85
|
+
[GitHub#82][Reported by krororo]
|
86
|
+
|
87
|
+
* Fixed a bug that `:skip_lines` doesn't work with multibyte characters data.
|
88
|
+
[GitHub#83][Reported by ff2248]
|
89
|
+
|
90
|
+
### Thanks
|
91
|
+
|
92
|
+
* Alyssa Ross
|
93
|
+
|
94
|
+
* 284km
|
95
|
+
|
96
|
+
* Chi Leung
|
97
|
+
|
98
|
+
* Danillo Souza
|
99
|
+
|
100
|
+
* Andrés Torres
|
101
|
+
|
102
|
+
* Genadi Samokovarov
|
103
|
+
|
104
|
+
* krororo
|
105
|
+
|
106
|
+
* ff2248
|
107
|
+
|
108
|
+
## 3.0.4 - 2019-01-25
|
109
|
+
|
110
|
+
### Improvements
|
111
|
+
|
112
|
+
* Removed duplicated `CSV::Row#include?` implementations.
|
113
|
+
[GitHub#69][Patch by Max Schwenk]
|
114
|
+
|
115
|
+
* Removed duplicated `CSV::Row#header?` implementations.
|
116
|
+
[GitHub#70][Patch by Max Schwenk]
|
117
|
+
|
118
|
+
### Fixes
|
119
|
+
|
120
|
+
* Fixed a typo in document.
|
121
|
+
[GitHub#72][Patch by Artur Beljajev]
|
122
|
+
|
123
|
+
* Fixed a compatibility bug when row headers are changed.
|
124
|
+
[GitHub#71][Reported by tomoyuki kosaka]
|
125
|
+
|
126
|
+
### Thanks
|
127
|
+
|
128
|
+
* Max Schwenk
|
129
|
+
|
130
|
+
* Artur Beljajev
|
131
|
+
|
132
|
+
* tomoyuki kosaka
|
133
|
+
|
134
|
+
## 3.0.3 - 2019-01-12
|
135
|
+
|
136
|
+
### Improvements
|
137
|
+
|
138
|
+
* Migrated benchmark tool to benchmark-driver from benchmark-ips.
|
139
|
+
[GitHub#57][Patch by 284km]
|
140
|
+
|
141
|
+
* Added `liberal_parsing: {double_quote_outside_quote: true}` parse
|
142
|
+
option.
|
143
|
+
[GitHub#66][Reported by Watson]
|
144
|
+
|
145
|
+
* Added `quote_empty:` write option.
|
146
|
+
[GitHub#35][Reported by Dave Myron]
|
147
|
+
|
148
|
+
### Fixes
|
149
|
+
|
150
|
+
* Fixed a compatibility bug that `CSV.generate` always return
|
151
|
+
`ASCII-8BIT` encoding string.
|
152
|
+
[GitHub#63][Patch by Watson]
|
153
|
+
|
154
|
+
* Fixed a compatibility bug that `CSV.parse("", headers: true)`
|
155
|
+
doesn't return `CSV::Table`.
|
156
|
+
[GitHub#64][Reported by Watson][Patch by 284km]
|
157
|
+
|
158
|
+
* Fixed a compatibility bug that multiple-characters column
|
159
|
+
separator doesn't work.
|
160
|
+
[GitHub#67][Reported by Jesse Reiss]
|
161
|
+
|
162
|
+
* Fixed a compatibility bug that double `#each` parse twice.
|
163
|
+
[GitHub#68][Reported by Max Schwenk]
|
164
|
+
|
165
|
+
### Thanks
|
166
|
+
|
167
|
+
* Watson
|
168
|
+
|
169
|
+
* 284km
|
170
|
+
|
171
|
+
* Jesse Reiss
|
172
|
+
|
173
|
+
* Dave Myron
|
174
|
+
|
175
|
+
* Max Schwenk
|
176
|
+
|
177
|
+
## 3.0.2 - 2018-12-23
|
178
|
+
|
179
|
+
### Improvements
|
180
|
+
|
181
|
+
* Changed to use strscan in parser.
|
182
|
+
[GitHub#52][Patch by 284km]
|
183
|
+
|
184
|
+
* Improves CSV write performance.
|
185
|
+
3.0.2 will be about 2 times faster than 3.0.1.
|
186
|
+
|
187
|
+
* Improves CSV parse performance for complex case.
|
188
|
+
3.0.2 will be about 2 times faster than 3.0.1.
|
189
|
+
|
190
|
+
### Fixes
|
191
|
+
|
192
|
+
* Fixed a parse error bug for new line only input with `headers` option.
|
193
|
+
[GitHub#53][Reported by Chris Beer]
|
194
|
+
|
195
|
+
* Fixed some typos in document.
|
196
|
+
[GitHub#54][Patch by Victor Shepelev]
|
197
|
+
|
198
|
+
### Thanks
|
199
|
+
|
200
|
+
* 284km
|
201
|
+
|
202
|
+
* Chris Beer
|
203
|
+
|
204
|
+
* Victor Shepelev
|
205
|
+
|
206
|
+
## 3.0.1 - 2018-12-07
|
207
|
+
|
208
|
+
### Improvements
|
209
|
+
|
210
|
+
* Added a test.
|
211
|
+
[GitHub#38][Patch by 284km]
|
212
|
+
|
213
|
+
* `CSV::Row#dup`: Changed to duplicate internal data.
|
214
|
+
[GitHub#39][Reported by André Guimarães Sakata]
|
215
|
+
|
216
|
+
* Documented `:nil_value` and `:empty_value` options.
|
217
|
+
[GitHub#41][Patch by OwlWorks]
|
218
|
+
|
219
|
+
* Added support for separator detection for non-seekable inputs.
|
220
|
+
[GitHub#45][Patch by Ilmari Karonen]
|
221
|
+
|
222
|
+
* Removed needless code.
|
223
|
+
[GitHub#48][Patch by Espartaco Palma]
|
224
|
+
|
225
|
+
* Added support for parsing header only CSV with `headers: true`.
|
226
|
+
[GitHub#47][Patch by Kazuma Shibasaka]
|
227
|
+
|
228
|
+
* Added support for coverage report in CI.
|
229
|
+
[GitHub#48][Patch by Espartaco Palma]
|
230
|
+
|
231
|
+
* Improved auto CR row separator detection.
|
232
|
+
[GitHub#51][Reported by Yuki Kurihara]
|
233
|
+
|
234
|
+
### Fixes
|
235
|
+
|
236
|
+
* Fixed a typo in document.
|
237
|
+
[GitHub#40][Patch by Marcus Stollsteimer]
|
238
|
+
|
239
|
+
### Thanks
|
240
|
+
|
241
|
+
* 284km
|
242
|
+
|
243
|
+
* André Guimarães Sakata
|
244
|
+
|
245
|
+
* Marcus Stollsteimer
|
246
|
+
|
247
|
+
* OwlWorks
|
248
|
+
|
249
|
+
* Ilmari Karonen
|
250
|
+
|
251
|
+
* Espartaco Palma
|
252
|
+
|
253
|
+
* Kazuma Shibasaka
|
254
|
+
|
255
|
+
* Yuki Kurihara
|
256
|
+
|
257
|
+
## 3.0.0 - 2018-06-06
|
258
|
+
|
259
|
+
### Fixes
|
260
|
+
|
261
|
+
* Fixed a bug that header isn't returned for empty row.
|
262
|
+
[GitHub#37][Patch by Grace Lee]
|
263
|
+
|
264
|
+
### Thanks
|
265
|
+
|
266
|
+
* Grace Lee
|
267
|
+
|
268
|
+
## 1.0.2 - 2018-05-03
|
269
|
+
|
270
|
+
### Improvements
|
271
|
+
|
272
|
+
* Split file for CSV::VERSION
|
273
|
+
|
274
|
+
* Code cleanup: Split csv.rb into a more manageable structure
|
275
|
+
[GitHub#19][Patch by Espartaco Palma]
|
276
|
+
[GitHub#20][Patch by Steven Daniels]
|
277
|
+
|
278
|
+
* Use CSV::MalformedCSVError for invalid encoding line
|
279
|
+
[GitHub#26][Reported by deepj]
|
280
|
+
|
281
|
+
* Support implicit Row <-> Array conversion
|
282
|
+
[Bug #10013][ruby-core:63582][Reported by Dawid Janczak]
|
283
|
+
|
284
|
+
* Update class docs
|
285
|
+
[GitHub#32][Patch by zverok]
|
286
|
+
|
287
|
+
* Add `Row#each_pair`
|
288
|
+
[GitHub#33][Patch by zverok]
|
289
|
+
|
290
|
+
* Improve CSV performance
|
291
|
+
[GitHub#30][Patch by Watson]
|
292
|
+
|
293
|
+
* Add :nil_value and :empty_value option
|
294
|
+
|
295
|
+
### Fixes
|
296
|
+
|
297
|
+
* Fix a bug that "bom|utf-8" doesn't work
|
298
|
+
[GitHub#23][Reported by Pavel Lobashov]
|
299
|
+
|
300
|
+
* `CSV::Row#to_h`, `#to_hash`: uses the same value as `Row#[]`
|
301
|
+
[Bug #14482][Reported by tomoya ishida]
|
302
|
+
|
303
|
+
* Make row separator detection more robust
|
304
|
+
[GitHub#25][Reported by deepj]
|
305
|
+
|
306
|
+
* Fix a bug that too much separator when col_sep is `" "`
|
307
|
+
[Bug #8784][ruby-core:63582][Reported by Sylvain Laperche]
|
308
|
+
|
309
|
+
### Thanks
|
310
|
+
|
311
|
+
* Espartaco Palma
|
312
|
+
|
313
|
+
* Steven Daniels
|
314
|
+
|
315
|
+
* deepj
|
316
|
+
|
317
|
+
* Dawid Janczak
|
318
|
+
|
319
|
+
* zverok
|
320
|
+
|
321
|
+
* Watson
|
322
|
+
|
323
|
+
* Pavel Lobashov
|
324
|
+
|
325
|
+
* tomoya ishida
|
326
|
+
|
327
|
+
* Sylvain Laperche
|
328
|
+
|
329
|
+
* Ryunosuke Sato
|
330
|
+
|
331
|
+
## 1.0.1 - 2018-02-09
|
332
|
+
|
333
|
+
### Improvements
|
334
|
+
|
335
|
+
* `CSV::Table#delete`: Added bulk delete support. You can delete
|
336
|
+
multiple rows and columns at once.
|
337
|
+
[GitHub#4][Patch by Vladislav]
|
338
|
+
|
339
|
+
* Updated Gem description.
|
340
|
+
[GitHub#11][Patch by Marcus Stollsteimer]
|
341
|
+
|
342
|
+
* Code cleanup.
|
343
|
+
[GitHub#12][Patch by Marcus Stollsteimer]
|
344
|
+
[GitHub#14][Patch by Steven Daniels]
|
345
|
+
[GitHub#18][Patch by takkanm]
|
346
|
+
|
347
|
+
* `CSV::Table#dig`: Added.
|
348
|
+
[GitHub#15][Patch by Tomohiro Ogoke]
|
349
|
+
|
350
|
+
* `CSV::Row#dig`: Added.
|
351
|
+
[GitHub#15][Patch by Tomohiro Ogoke]
|
352
|
+
|
353
|
+
* Added ISO 8601 support to date time converter.
|
354
|
+
[GitHub#16]
|
355
|
+
|
356
|
+
### Fixes
|
357
|
+
|
358
|
+
* Fixed wrong `CSV::VERSION`.
|
359
|
+
[GitHub#10][Reported by Marcus Stollsteimer]
|
360
|
+
|
361
|
+
* `CSV.generate`: Fixed a regression bug that `String` argument is
|
362
|
+
ignored.
|
363
|
+
[GitHub#13][Patch by pavel]
|
364
|
+
|
365
|
+
### Thanks
|
366
|
+
|
367
|
+
* Vladislav
|
368
|
+
|
369
|
+
* Marcus Stollsteimer
|
370
|
+
|
371
|
+
* Steven Daniels
|
372
|
+
|
373
|
+
* takkanm
|
374
|
+
|
375
|
+
* Tomohiro Ogoke
|
376
|
+
|
377
|
+
* pavel
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# CSV
|
2
2
|
|
3
3
|
[](https://travis-ci.org/ruby/csv)
|
4
|
+
[](https://codeclimate.com/github/ruby/csv/test_coverage)
|
4
5
|
|
5
6
|
This library provides a complete interface to CSV files and data. It offers tools to enable you to read and write to and from Strings or IO objects, as needed.
|
6
7
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This provides String#delete_suffix? for Ruby 2.4.
|
4
|
+
unless String.method_defined?(:delete_suffix)
|
5
|
+
class CSV
|
6
|
+
module DeleteSuffix
|
7
|
+
refine String do
|
8
|
+
def delete_suffix(suffix)
|
9
|
+
if end_with?(suffix)
|
10
|
+
self[0...-suffix.size]
|
11
|
+
else
|
12
|
+
self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class CSV
|
4
|
+
class FieldsConverter
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(options={})
|
8
|
+
@converters = []
|
9
|
+
@nil_value = options[:nil_value]
|
10
|
+
@empty_value = options[:empty_value]
|
11
|
+
@empty_value_is_empty_string = (@empty_value == "")
|
12
|
+
@accept_nil = options[:accept_nil]
|
13
|
+
@builtin_converters = options[:builtin_converters]
|
14
|
+
@need_static_convert = need_static_convert?
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_converter(name=nil, &converter)
|
18
|
+
if name.nil? # custom converter
|
19
|
+
@converters << converter
|
20
|
+
else # named converter
|
21
|
+
combo = @builtin_converters[name]
|
22
|
+
case combo
|
23
|
+
when Array # combo converter
|
24
|
+
combo.each do |sub_name|
|
25
|
+
add_converter(sub_name)
|
26
|
+
end
|
27
|
+
else # individual named converter
|
28
|
+
@converters << combo
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def each(&block)
|
34
|
+
@converters.each(&block)
|
35
|
+
end
|
36
|
+
|
37
|
+
def empty?
|
38
|
+
@converters.empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
def convert(fields, headers, lineno)
|
42
|
+
return fields unless need_convert?
|
43
|
+
|
44
|
+
fields.collect.with_index do |field, index|
|
45
|
+
if field.nil?
|
46
|
+
field = @nil_value
|
47
|
+
elsif field.empty?
|
48
|
+
field = @empty_value unless @empty_value_is_empty_string
|
49
|
+
end
|
50
|
+
@converters.each do |converter|
|
51
|
+
break if field.nil? and @accept_nil
|
52
|
+
if converter.arity == 1 # straight field converter
|
53
|
+
field = converter[field]
|
54
|
+
else # FieldInfo converter
|
55
|
+
if headers
|
56
|
+
header = headers[index]
|
57
|
+
else
|
58
|
+
header = nil
|
59
|
+
end
|
60
|
+
field = converter[field, FieldInfo.new(index, lineno, header)]
|
61
|
+
end
|
62
|
+
break unless field.is_a?(String) # short-circuit pipeline for speed
|
63
|
+
end
|
64
|
+
field # final state of each field, converted or original
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
def need_static_convert?
|
70
|
+
not (@nil_value.nil? and @empty_value_is_empty_string)
|
71
|
+
end
|
72
|
+
|
73
|
+
def need_convert?
|
74
|
+
@need_static_convert or
|
75
|
+
(not @converters.empty?)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/csv/match_p.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This provides String#match? and Regexp#match? for Ruby 2.3.
|
4
|
+
unless String.method_defined?(:match?)
|
5
|
+
class CSV
|
6
|
+
module MatchP
|
7
|
+
refine String do
|
8
|
+
def match?(pattern)
|
9
|
+
self =~ pattern
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
refine Regexp do
|
14
|
+
def match?(string)
|
15
|
+
self =~ string
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|