dsv 0.16.0 → 0.16.1
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 +11 -0
- data/README.md +1 -1
- data/TODO +38 -28
- data/lib/DSV/VERSION.rb +1 -1
- data/lib/dsv.rb +4 -3
- data/test/dsv_test.rb +12 -6
- 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: 998074c09bc9f636ccd0c0c7b6d73d78ceeda4a0efccafedcbc26c72cbec947d
|
|
4
|
+
data.tar.gz: 28549e92a6760f7c7ac536d1a12c886aeb7f17c920e26f4b8454e9cb5a379727
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b91d4255ea53e6a699e5f04d69d10b2cbdd5c07439c93fa755ce9c088446f9f329a419b0fd1d4a746e7582609264ede1b4ed9a8f5f6816b6115069fc13b9fa90
|
|
7
|
+
data.tar.gz: 87e13881fcad93d7dd7558e985ae7ef719f2f104a2eb4651192cc3a17ba9c27b99146def74b24e2ca6e3352d35ccee20507db99e9f904fc0896b078d8c01fb7a
|
data/CHANGELOG
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## 20261126
|
|
4
4
|
|
|
5
|
+
0.16.1: ~ DSV.open: A file not yet there is written by name under w, w+, a and a+.
|
|
6
|
+
|
|
7
|
+
1. ~ DSV.source_type: Under w, w+, a and a+, a String is a path. A file not yet there had been taken as text, and the rows written to it lost in a StringIO.
|
|
8
|
+
2. ~ initialize(): The mode is given to source_type.
|
|
9
|
+
3. ~ test/dsv_test.rb: Writing a new file by name under w, w+, a and a+ is tested, where it was skipped, and so is source_type under each mode.
|
|
10
|
+
4. ~ README.md: Under w, w+, a or a+, a String is a path.
|
|
11
|
+
5. ~ TODO: Modes as declarations is split into Modes by name, Nothing ignored, Column names in one place, and Path or text. The spacey modes reading what they write is a job, and the jobs are renumbered.
|
|
12
|
+
6. ~ ROADMAP.md: 0.17.0 is modes by name, 0.18.0 nothing ignored, 0.19.0 column names in one place, 0.20.0 path or text, and streaming 0.21.0.
|
|
13
|
+
7. ~ PROPOSED.md: Path or text asks whether a String can be text under a mode which writes.
|
|
14
|
+
8. ~ DSV::VERSION: /0.16.0/0.16.1/
|
|
15
|
+
|
|
5
16
|
0.16.0: + DSV.filter: An alias of DSV.select.
|
|
6
17
|
|
|
7
18
|
1. + DSV.filter: An alias of select, as find_all is.
|
data/README.md
CHANGED
|
@@ -47,7 +47,7 @@ DSV.read("1,2,3\n4,5,6\n", as_array: true)
|
|
|
47
47
|
# => [["1", "2", "3"], ["4", "5", "6"]]
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
A String that names an existing file is read as a file; any other String is read as text.
|
|
50
|
+
A String that names an existing file is read as a file; any other String is read as text. Under `w`, `w+`, `a` or `a+` a String is always a path, so that a file not yet there can be written by name.
|
|
51
51
|
|
|
52
52
|
### Selecting columns
|
|
53
53
|
|
data/TODO
CHANGED
|
@@ -1,44 +1,54 @@
|
|
|
1
1
|
# TODO
|
|
2
2
|
|
|
3
|
-
## Modes
|
|
3
|
+
## Modes by name
|
|
4
|
+
|
|
5
|
+
1. :unspecified, the name of the default, which quote returns where no mode is given.
|
|
6
|
+
2. :unquoted, the name of the mode reading no quotes, :none kept as an alias.
|
|
7
|
+
3. The reader chosen once, when the quote mode is set, as row_renderer is for writing, the two from one list of names and their aliases.
|
|
8
|
+
4. The spacey modes read as their unspaced modes are, with a space after each separator.
|
|
9
|
+
|
|
10
|
+
## Nothing ignored
|
|
11
|
+
|
|
12
|
+
5. An unknown quote mode, file mode or option raises ArgumentError, as does an argument which new does not take.
|
|
13
|
+
|
|
14
|
+
## Column names in one place
|
|
4
15
|
|
|
5
|
-
1. An unknown quote mode, file mode or option raises ArgumentError.
|
|
6
|
-
2. :unspecified, the name of the default.
|
|
7
|
-
3. :unquoted, the name of the mode reading no quotes, :none kept as an alias.
|
|
8
|
-
4. The reader chosen once, when the quote mode is set, as row_renderer is for writing.
|
|
9
|
-
5. .read and .open taking a path, and .parse text; a path which does not exist raising, and nothing inferred from whether a file exists.
|
|
10
16
|
6. attributes= setting columns, attributes always worked out from columns; rows read afterwards keyed by those names.
|
|
11
17
|
|
|
18
|
+
## Path or text
|
|
19
|
+
|
|
20
|
+
7. .read and .open taking a path, and .parse text; a path which does not exist raising, and nothing inferred from whether a file exists.
|
|
21
|
+
|
|
12
22
|
## Streaming
|
|
13
23
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
8. each yields each row as it is read.
|
|
25
|
+
9. each returns its receiver.
|
|
26
|
+
10. rows no longer filled by each.
|
|
27
|
+
11. Chunks from each_slice.
|
|
28
|
+
12. The source read once, start to end, with no rewind; the header from the first row read.
|
|
29
|
+
13. The line of an error found by seeking only where the source can.
|
|
30
|
+
14. A rewind left to r+ rewriting and to first_row called alone.
|
|
21
31
|
|
|
22
32
|
## Checked and measured
|
|
23
33
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
15. 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.
|
|
35
|
+
16. A benchmark script against stdlib CSV, and the README's speed sentence written from its output.
|
|
36
|
+
17. The README showing every mode by example, and a table matching each to stdlib CSV's and Python's settings.
|
|
27
37
|
|
|
28
38
|
## Speed, results unchanged
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
18. A per-row fast path for the default: split, the fields bare or wrapped in two quotes unwrapped, any other row read in full.
|
|
41
|
+
19. as_array: returning the split fields, rather than building a Hash and then an Array from it.
|
|
42
|
+
20. Rows built by zip.to_h.
|
|
43
|
+
21. The scanner-based parser, at the tag scanner-parser-20261006, judged against the string operations used now.
|
|
34
44
|
|
|
35
45
|
## Features
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
22. :rfc_4180, a quote mode reading what RFC 4180 allows as :unspecified does and raising on what it forbids.
|
|
48
|
+
23. field_count:, :header or an Integer, off by default; a row of another width raising.
|
|
49
|
+
24. Writing with minimal quoting: a field quoted only where it holds a separator, a quote or a row terminator.
|
|
50
|
+
25. A line number in each parse error, and line_numbers:.
|
|
51
|
+
26. headers?, the instance-level header_row renamed, header_row kept as an alias.
|
|
52
|
+
27. <<, to append a row, and generate, to build a string.
|
|
53
|
+
28. Symbols and Strings interchangeable for column names, in a selection, a columns: list and a row's keys.
|
|
54
|
+
29. Duplicate headers by option: all kept as an Array, the default; indexed, a, a.1; first; last; error.
|
data/lib/DSV/VERSION.rb
CHANGED
data/lib/dsv.rb
CHANGED
|
@@ -32,8 +32,9 @@ class DSV
|
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
# A String is a path under a mode which writes, so that a file not yet there can be written by name, and otherwise where it names a file; any other String is text.
|
|
36
|
+
def source_type(source, mode = nil)
|
|
37
|
+
if ['w', 'w+', 'a', 'a+'].include?(normalised_mode(mode)) || ::File.exist?(source)
|
|
37
38
|
DSV::File
|
|
38
39
|
else
|
|
39
40
|
DSV::String
|
|
@@ -335,7 +336,7 @@ class DSV
|
|
|
335
336
|
options = DSV.extract_options(args)
|
|
336
337
|
@source = (
|
|
337
338
|
if source.is_a?(::String)
|
|
338
|
-
DSV.source_type(source).source(source, options)
|
|
339
|
+
DSV.source_type(source, options[:mode]).source(source, options)
|
|
339
340
|
else
|
|
340
341
|
source
|
|
341
342
|
end
|
data/test/dsv_test.rb
CHANGED
|
@@ -359,6 +359,11 @@ describe DSV do
|
|
|
359
359
|
with_file{|path| _(DSV.source_type(path)).must_equal DSV::File}
|
|
360
360
|
_(DSV.source_type(DATA)).must_equal DSV::String
|
|
361
361
|
end
|
|
362
|
+
|
|
363
|
+
it "is DSV::File for any String under a mode which writes" do
|
|
364
|
+
['w', 'w+', 'a', 'a+', :append, 'write_only'].each{|mode| _(DSV.source_type('new.csv', mode)).must_equal DSV::File}
|
|
365
|
+
['r', 'r+', nil].each{|mode| _(DSV.source_type('new.csv', mode)).must_equal DSV::String}
|
|
366
|
+
end
|
|
362
367
|
end
|
|
363
368
|
|
|
364
369
|
describe ".new" do
|
|
@@ -914,12 +919,13 @@ describe DSV do
|
|
|
914
919
|
end
|
|
915
920
|
end
|
|
916
921
|
|
|
917
|
-
it "writes a new file by name under a
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
922
|
+
it "writes a new file by name under w, w+, a and a+" do
|
|
923
|
+
['w', 'w+', 'a', 'a+'].each do |mode|
|
|
924
|
+
with_file do |path, directory|
|
|
925
|
+
new_path = File.join(directory, 'new.csv')
|
|
926
|
+
DSV.open(new_path, mode: mode, headers: true, columns: [:a, :b], quote: :none){|csv| csv.rows = [{'a' => 1, 'b' => 2}]; csv.write}
|
|
927
|
+
_(File.read(new_path)).must_equal "a,b\n1,2\n"
|
|
928
|
+
end
|
|
923
929
|
end
|
|
924
930
|
end
|
|
925
931
|
|