dsv.rb 0.12.12 → 0.12.13
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/CHANGELOG +8 -0
- data/TODO +24 -25
- data/lib/DSV/VERSION.rb +1 -1
- data/lib/dsv.rb +2 -2
- data/test/dsv_test.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0ca4abca7cb6bd9076317aadd692522f0c182e5b59a3fb446f03914de15f9cb4
|
|
4
|
+
data.tar.gz: e1000934e68b46f82f268963ef9658f45d64f7aeb53a91e4601ce5de45995608
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6869a34fc41967008c873dd888a34fa82f08791ab180a7271a4c68f0c1ee7d6f0e1fdf79a0729711afa4fe6e3c812a4877ff47f5cba6fc5843c03ef5ee7279c
|
|
7
|
+
data.tar.gz: fead5bc4cb84b50a9e0698442fc4f7964e31a6cfd3ea4bacfea16c32780180711d57ffe77c9be7556001f3302a5413da52b78b75bf4a3eb8fda5b541a4981d13
|
data/CHANGELOG
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## 20261103
|
|
4
4
|
|
|
5
|
+
0.12.13: reading honours quote:, given as a String or to DSV.parse_line.
|
|
6
|
+
|
|
7
|
+
1. ~ split_row(): reads a quote mode given as a String as its Symbol, as row_renderer() does. A String mode had been read as unspecified.
|
|
8
|
+
2. ~ DSV.parse_line: passes quote: on, rather than always reading as unspecified; its options to DSV.new written key: value, not with hashrockets.
|
|
9
|
+
3. ~ test/dsv_test.rb: + quote: given as a String on read; + parse_line with quote:.
|
|
10
|
+
4. ~ TODO: - 1.
|
|
11
|
+
5. ~ lib/DSV/VERSION.rb: /0.12.12/0.12.13/.
|
|
12
|
+
|
|
5
13
|
0.12.12: as_array: with a column selection gives the columns selected.
|
|
6
14
|
|
|
7
15
|
1. ~ parse_fields(): under as_array:, a selection gives the selected fields; + positions(). Each column not selected had come back as nil, and a selection by position had lost its values.
|
data/TODO
CHANGED
|
@@ -2,43 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
## 0.12.x, fixes
|
|
4
4
|
|
|
5
|
-
1.
|
|
6
|
-
2.
|
|
7
|
-
3. :
|
|
8
|
-
4.
|
|
9
|
-
5.
|
|
10
|
-
6.
|
|
11
|
-
7. The internals private.
|
|
5
|
+
1. A space as the column separator splits on each space, not as String#split(' ') does.
|
|
6
|
+
2. :double back to 0.12.4's reading, undoing 0.12.5 item 2: a row not starting with a quote split plainly, one starting with a quote split on quote-separator-quote, and one which leaves a lone quote in a field read in full as wholly quoted. The README back to 0.12.3's wording.
|
|
7
|
+
3. :single read, as :double is with a single quote.
|
|
8
|
+
4. filter, a class-level alias of select.
|
|
9
|
+
5. A String under a write mode taken as a path, so that a file not yet there can be written by name.
|
|
10
|
+
6. The internals private.
|
|
12
11
|
|
|
13
12
|
## 0.13.0, modes as declarations
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
7. An unknown quote mode, file mode or option raises ArgumentError, where each is ignored today.
|
|
15
|
+
8. :mixed, the name of the default.
|
|
16
|
+
9. A mode raises on a contradiction which costs nothing to see, every row alike, header included: under :double, a row not starting with a quote, and a bare field in a row read in full. Declaring :mixed reads such a row.
|
|
18
17
|
|
|
19
18
|
## 0.14.0, streaming
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
10. each yields each row as it is read and returns its receiver, so that detect and break stop reading and memory does not grow with the file; rows is no longer filled by each. Chunks come from each_slice. A source read once, start to end, with no rewind, so that a pipe or $stdin can be read: the header from the first row read, and the line of an error found by seeking only where the source can; a rewind left to r+ rewriting and first_row called alone.
|
|
22
21
|
|
|
23
22
|
## 1.0
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
11. A corpus in the tests, a day of NEMWEB's dispatch files trimmed and the RFC 4180 cases, each checked against stdlib CSV's rows.
|
|
25
|
+
12. A benchmark script against stdlib CSV, and the README's speed sentence written from its output.
|
|
26
|
+
13. README: every mode by example, and a table matching each to stdlib CSV's and Python's settings.
|
|
28
27
|
|
|
29
28
|
## 1.x, speed, results unchanged
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
14. A per-row fast path for the default: split, the fields bare or wrapped in two quotes unwrapped, any other row read in full.
|
|
31
|
+
15. as_array: returning the split fields, rather than building a Hash and then an Array from it.
|
|
32
|
+
16. The splitter chosen once, at construction, as row_renderer is for writing.
|
|
33
|
+
17. Two string predicates in place of four regex matches per piece; rows built by zip.to_h; the scanner-based parser, at the tag scanner-parser-20261006, judged against the rest.
|
|
35
34
|
|
|
36
35
|
## 1.x, features
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
37
|
+
18. :rfc_4180, a quote mode reading what RFC 4180 allows as :mixed does and raising on what it forbids.
|
|
38
|
+
19. field_count:, :header or an Integer, off by default: a row of another width raises.
|
|
39
|
+
20. Writing: minimal quoting, a field quoted only where it holds a separator, a quote or a row terminator; a row terminator inside a field kept, quoted, or folded to a space; the encoding declared and a transcode offered with any loss marked.
|
|
40
|
+
21. A line number in each parse error, found only when the error is raised, as UnterminatedQuote finds its, where the source can seek. line_numbers:, off by default, counts lines as it reads instead, for any source a pipe included: the read loop chosen once, at construction, as row_renderer is for writing, so that without it no row pays for the count.
|
|
41
|
+
22. The instance-level header_row renamed headers?, kept as an alias; << to append a row and generate to build a string.
|
|
42
|
+
23. Symbols and Strings interchangeable for column names, in a selection, a columns: list and a row's keys.
|
|
43
|
+
24. The duplicate-header modes as an option: keep all as an Array, the default; index, a, a.1; first; last; error.
|
data/lib/DSV/VERSION.rb
CHANGED
data/lib/dsv.rb
CHANGED
|
@@ -125,7 +125,7 @@ class DSV
|
|
|
125
125
|
options = DSV.extract_options(args)
|
|
126
126
|
row_separator = options[:row_separator] || options[:row_sep] || "\n"
|
|
127
127
|
column_separator = options[:column_separator] || options[:col_sep] || ','
|
|
128
|
-
sc = DSV.new(raw_row, :quote
|
|
128
|
+
sc = DSV.new(raw_row, quote: options[:quote], as_array: true, row_separator: row_separator, column_separator: column_separator)
|
|
129
129
|
sc.parse_row(raw_row)
|
|
130
130
|
end
|
|
131
131
|
|
|
@@ -271,7 +271,7 @@ class DSV
|
|
|
271
271
|
# One row into its fields, by the quote mode: :none splits; :double splits a row as it promises, wholly quoted or wholly unquoted, and one that is neither as unspecified would; unspecified splits and reassembles a quoted field that held the separator, a doubled quote inside it reading as one. nil where a quoted field in the row is still open at its end. Direct string operations throughout; the scanner-based parser is on the branch scanner-parser.
|
|
272
272
|
def split_row(raw_row)
|
|
273
273
|
row = raw_row.chomp(@row_separator)
|
|
274
|
-
case @quote
|
|
274
|
+
case @quote&.to_sym
|
|
275
275
|
when :none, :unquoted
|
|
276
276
|
split_on(row, @column_separator)
|
|
277
277
|
when :double, :double_quoted, :double_quotes
|
data/test/dsv_test.rb
CHANGED
|
@@ -262,6 +262,12 @@ describe DSV do
|
|
|
262
262
|
_(DSV.parse_line("1,2,3\r\n", row_sep: "\r\n")).must_equal ['1', '2', '3']
|
|
263
263
|
end
|
|
264
264
|
|
|
265
|
+
it "takes quote:" do
|
|
266
|
+
_(DSV.parse_line("\"a\",b\n", quote: :none)).must_equal ['"a"', 'b']
|
|
267
|
+
_(DSV.parse_line("\"a\",b\n", quote: 'none')).must_equal ['"a"', 'b']
|
|
268
|
+
_(DSV.parse_line("\"a,b\",\"c\"\n", quote: :double)).must_equal ['a,b', 'c']
|
|
269
|
+
end
|
|
270
|
+
|
|
265
271
|
it "leaves the caller's string as it was" do
|
|
266
272
|
line = "1,2,3\n"
|
|
267
273
|
DSV.parse_line(line)
|
|
@@ -564,6 +570,11 @@ describe DSV do
|
|
|
564
570
|
_(DSV.read("a,b\n\"x\",\"2\"\n", headers: true, quote: :none)).must_equal [{'a' => '"x"', 'b' => '"2"'}]
|
|
565
571
|
end
|
|
566
572
|
|
|
573
|
+
it "reads a quote mode given as a String as its Symbol, as writing does" do
|
|
574
|
+
_(DSV.read("a,b\n\"x\",\"2\"\n", headers: true, quote: 'none')).must_equal [{'a' => '"x"', 'b' => '"2"'}]
|
|
575
|
+
_(DSV.read("\"a\",\"b\"\n\"x\",\"2\"\n", headers: true, quote: 'double')).must_equal [{'a' => 'x', 'b' => '2'}]
|
|
576
|
+
end
|
|
577
|
+
|
|
567
578
|
it "strips the quotes under quote: :double, a row being wholly quoted or, as a header row often is, wholly unquoted" do
|
|
568
579
|
_(DSV.read("a,b\n\"x\",\"2\"\n", headers: true, quote: :double)).must_equal [{'a' => 'x', 'b' => '2'}]
|
|
569
580
|
_(DSV.read("\"a\",\"b\"\n\"say \"\"hi\"\"\",\"2\"\n", headers: true, quote: :double)).must_equal [{'a' => 'say "hi"', 'b' => '2'}]
|