dsv 0.13.0 → 0.13.2
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 +18 -0
- data/TODO +16 -17
- data/lib/DSV/VERSION.rb +1 -1
- data/lib/dsv.rb +13 -8
- data/test/dsv_test.rb +5 -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: 787d6487ec2bad00eb735730d35d376be8ef5feb7ef3f6189ea946dc7a2614cb
|
|
4
|
+
data.tar.gz: 8b6b56fbb850b2e590a629d92b27d25d920316b4b88a4239014cf56ecff8b281
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 72cfaca95da5a21ad1e8d950279c671517c8f036971c9c72df17ed666f1a6d6752f9e2b0dad32c6fdaf3e87cb13178795a3be0e23ed3a5ec4b435c79b58bb518
|
|
7
|
+
data.tar.gz: 6e82040587d79fe77fb47d1e11bed60aa52a099166388e40c73160a94de27f83a4cb48ec5cf4b5a3d3cc70a1fb23369f4ed132df9dccd9c3e4b5a24334430ef2
|
data/CHANGELOG
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# dsv/CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 20261126
|
|
4
|
+
|
|
5
|
+
0.13.2: Create a fast path, where no column name repeats, for writing, to_a, and reading as_array or by name, so that a write takes a third less time.
|
|
6
|
+
|
|
7
|
+
1. ~ values_in_order(): Where no name repeats, the row's values are taken with values_at, no field being looked at. From 0.11.5 every field of every row was checked for an Array, which took about 40% of a write.
|
|
8
|
+
2. ~ parse_fields(): Under a selection by name, where no name repeats, each field is assigned rather than passed to store_field().
|
|
9
|
+
3. ~ DSV::VERSION: /0.13.1/0.13.2/
|
|
10
|
+
|
|
11
|
+
## 20261125
|
|
12
|
+
|
|
13
|
+
0.13.1: ~ DSV#write: Ensure that rows with header a,a,b don't lose the duplicate column name and are written back as a,a,b.
|
|
14
|
+
|
|
15
|
+
1. ~ write(): The columns taken from the first row's keys give a name whose value is an Array once for each of its values, as 0.11.5 meant a repeated column to round-trip.
|
|
16
|
+
2. ~ test/dsv_test.rb: A repeated name is written from the rows' keys, from rows given and from rows read.
|
|
17
|
+
3. ~ TODO: The job for write is gone.
|
|
18
|
+
4. ~ ROADMAP.md: 0.13.x no longer lists it.
|
|
19
|
+
5. ~ DSV::VERSION: /0.13.0/0.13.1/
|
|
20
|
+
|
|
3
21
|
## 20261124
|
|
4
22
|
|
|
5
23
|
0.13.0: Under :double, a row which breaks it raises, where from 0.12.5 to 0.12.15 it was read as unspecified.
|
data/TODO
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
# TODO
|
|
2
2
|
|
|
3
|
-
1.
|
|
4
|
-
2.
|
|
5
|
-
3.
|
|
6
|
-
4.
|
|
7
|
-
5. :
|
|
8
|
-
6.
|
|
9
|
-
7.
|
|
10
|
-
8.
|
|
11
|
-
9.
|
|
12
|
-
10.
|
|
13
|
-
11. each
|
|
14
|
-
12.
|
|
15
|
-
13.
|
|
16
|
-
14.
|
|
17
|
-
15. The
|
|
18
|
-
16.
|
|
19
|
-
17. A rewind left to r+ rewriting and to first_row called alone.
|
|
3
|
+
1. filter, a class-level alias of select.
|
|
4
|
+
2. The internals private, and split_double_quoted() renamed split_wholly_quoted().
|
|
5
|
+
3. An unknown quote mode, file mode or option raises ArgumentError.
|
|
6
|
+
4. :unspecified, the name of the default.
|
|
7
|
+
5. :unquoted, the name of the mode reading no quotes, :none kept as an alias.
|
|
8
|
+
6. The reader chosen once, when the quote mode is set, as row_renderer is for writing.
|
|
9
|
+
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.
|
|
10
|
+
8. :single read as :double is, with a single quote.
|
|
11
|
+
9. attributes= setting columns, attributes always worked out from columns; rows read afterwards keyed by those names.
|
|
12
|
+
10. each yields each row as it is read.
|
|
13
|
+
11. each returns its receiver.
|
|
14
|
+
12. rows no longer filled by each.
|
|
15
|
+
13. Chunks from each_slice.
|
|
16
|
+
14. The source read once, start to end, with no rewind; the header from the first row read.
|
|
17
|
+
15. The line of an error found by seeking only where the source can.
|
|
18
|
+
16. A rewind left to r+ rewriting and to first_row called alone.
|
data/lib/DSV/VERSION.rb
CHANGED
data/lib/dsv.rb
CHANGED
|
@@ -258,8 +258,9 @@ class DSV
|
|
|
258
258
|
end
|
|
259
259
|
end
|
|
260
260
|
|
|
261
|
-
# A row's values in position order
|
|
261
|
+
# A row's values in position order. Under a name at several positions the row holds an Array, whose values go back to those positions in turn; a single value under such a name goes at each. Where no name repeats, the values are taken as they are, sparing a check of every field.
|
|
262
262
|
def values_in_order(row)
|
|
263
|
+
return row.values_at(*attributes) if repeated_names.empty?
|
|
263
264
|
occurrence = ::Hash.new(0)
|
|
264
265
|
attributes.collect do |name|
|
|
265
266
|
value = row[name]
|
|
@@ -449,7 +450,11 @@ class DSV
|
|
|
449
450
|
when Integer
|
|
450
451
|
fields.each{|column_value| parsed_row[i] = column_value unless !selected_columns.include?(i += 1)}
|
|
451
452
|
else
|
|
452
|
-
|
|
453
|
+
if repeated_names.empty?
|
|
454
|
+
fields.each{|column_value| parsed_row[attributes[i]] = column_value unless !selected_columns.include?(attributes[i += 1])}
|
|
455
|
+
else
|
|
456
|
+
fields.each{|column_value| store_field(parsed_row, attributes[i], column_value) unless !selected_columns.include?(attributes[i += 1])}
|
|
457
|
+
end
|
|
453
458
|
end
|
|
454
459
|
end
|
|
455
460
|
if @as_array
|
|
@@ -463,15 +468,15 @@ class DSV
|
|
|
463
468
|
end
|
|
464
469
|
end
|
|
465
470
|
|
|
466
|
-
# The positions of the columns selected, in column order, a repeated name giving each of its own.
|
|
467
|
-
def positions(selected_columns)
|
|
468
|
-
|
|
469
|
-
end
|
|
471
|
+
# The positions of the columns selected, in column order, a repeated name giving each of its own.
|
|
472
|
+
def positions(selected_columns)
|
|
473
|
+
selected_columns.flat_map{|column| column.is_a?(::Integer) ? column : Array((columns || {})[column])}.sort
|
|
474
|
+
end
|
|
470
475
|
|
|
471
|
-
# With no columns defined, rows keyed by name supply them, and the header, from the first row's keys; rows keyed by position write positionally and have no header to write.
|
|
476
|
+
# With no columns defined, rows keyed by name supply them, and the header, from the first row's keys, a name whose value is an Array once for each of its values; rows keyed by position write positionally and have no header to write.
|
|
472
477
|
def write(*selected_columns)
|
|
473
478
|
prepare_to_rewrite if @mode == 'r+'
|
|
474
|
-
self.columns = @rows[0].
|
|
479
|
+
self.columns = @rows[0].flat_map{|name, value| value.is_a?(::Array) ? ::Array.new(value.size, name) : name} if blank?(columns) && @rows[0].is_a?(::Hash) && @rows[0].keys[0].is_a?(::String)
|
|
475
480
|
write_header(*selected_columns) if header_row? && attributes
|
|
476
481
|
each{|row| write_row(row, *selected_columns)}
|
|
477
482
|
end
|
data/test/dsv_test.rb
CHANGED
|
@@ -614,6 +614,11 @@ describe DSV do
|
|
|
614
614
|
_(written(columns: ['a', 'a', 'b'], quote: :none){|csv| csv.write_row('a' => 'x', 'b' => '3')}).must_equal "x,x,3\n"
|
|
615
615
|
end
|
|
616
616
|
|
|
617
|
+
it "writes a repeated name from the rows' keys where no columns are defined, each of its values in a field of its own" do
|
|
618
|
+
_(written(headers: true, quote: :none){|csv| csv.rows = [{'a' => ['1', '2'], 'b' => '3'}]; csv.write}).must_equal "a,a,b\n1,2,3\n"
|
|
619
|
+
_(written(headers: true){|csv| csv.rows = DSV.read("a,a,b\n1,2,3\n", headers: true); csv.write}).must_equal "\"a\",\"a\",\"b\"\n\"1\",\"2\",\"3\"\n"
|
|
620
|
+
end
|
|
621
|
+
|
|
617
622
|
it "reads a doubled quote as one quote in a row" do
|
|
618
623
|
_(DSV.read("a,b\n\"say \"\"hi\"\"\",2\n", headers: true)).must_equal [{'a' => 'say "hi"', 'b' => '2'}]
|
|
619
624
|
end
|