dsv 0.13.0 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db9ee29841ef9fa86e047c7c2793bc249fb6a565bc6f76f3a4fb0f24e12ee4b9
4
- data.tar.gz: 8cd6112162fd005f994a1d2db8699e791e547d0e8ee1f633628ecd246b490cac
3
+ metadata.gz: 42505a0423cb4ac1176c686e87420f4b15bd78df41c2d74f80d78e67bc793179
4
+ data.tar.gz: 180212c6a93ffa6d35598b6c669682ca6b00819dce9261f395add9600dfae3eb
5
5
  SHA512:
6
- metadata.gz: 7645c70c8ac8664ad7febcfe16db321a90ef334946535cf45a63582417cbde9d6353b4cd4fb991daa177b97ac4cd8f74d5e28ed92d422ba283c29676d036ea8b
7
- data.tar.gz: 2f932b86ad2fa36ed622b13cb88d5e425d51075b75f1c4a4f05e73eb47c03d18da52379b7618b8c5152d227b74ba8294da9b404772d5cf8696abf1bc4e78a86e
6
+ metadata.gz: 4f5bc856797a56a5b0d999974a4dc8ae53179aee464dac4b8feea85d57837110ea93891d33fa165472b38b70815c8fc9b11df4bfade4f87e755086e666d59950
7
+ data.tar.gz: 49b16c658401d362758c2abe1c02396c31423bd971e19b4a55c5fecafe2524b0890bc3ba57c96d8dd9f8bc0e0644ab5fcc165cacd290f8d564a8b2740dae3da5
data/CHANGELOG CHANGED
@@ -1,5 +1,15 @@
1
1
  # dsv/CHANGELOG
2
2
 
3
+ ## 20261125
4
+
5
+ 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.
6
+
7
+ 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.
8
+ 2. ~ test/dsv_test.rb: A repeated name is written from the rows' keys, from rows given and from rows read.
9
+ 3. ~ TODO: The job for write is gone.
10
+ 4. ~ ROADMAP.md: 0.13.x no longer lists it.
11
+ 5. ~ DSV::VERSION: /0.13.0/0.13.1/
12
+
3
13
  ## 20261124
4
14
 
5
15
  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. write with no columns defined keeping a repeated name, each of its values in a field of its own, where the Array is written whole into one field.
4
- 2. filter, a class-level alias of select.
5
- 3. The internals private, and split_double_quoted() renamed split_wholly_quoted().
6
- 4. An unknown quote mode, file mode or option raises ArgumentError.
7
- 5. :unspecified, the name of the default.
8
- 6. :unquoted, the name of the mode reading no quotes, :none kept as an alias.
9
- 7. The reader chosen once, when the quote mode is set, as row_renderer is for writing.
10
- 8. .read and .open taking a path, and .parse text; a path which does not exist raising, and nothing inferred from whether a file exists.
11
- 9. :single read as :double is, with a single quote.
12
- 10. attributes= setting columns, attributes always worked out from columns; rows read afterwards keyed by those names.
13
- 11. each yields each row as it is read.
14
- 12. each returns its receiver.
15
- 13. rows no longer filled by each.
16
- 14. Chunks from each_slice.
17
- 15. The source read once, start to end, with no rewind; the header from the first row read.
18
- 16. The line of an error found by seeking only where the source can.
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
@@ -2,5 +2,5 @@
2
2
  # DSV::VERSION
3
3
 
4
4
  class DSV
5
- VERSION = '0.13.0'
5
+ VERSION = '0.13.1'
6
6
  end
data/lib/dsv.rb CHANGED
@@ -468,10 +468,10 @@ def positions(selected_columns)
468
468
  selected_columns.flat_map{|column| column.is_a?(::Integer) ? column : Array((columns || {})[column])}.sort
469
469
  end
470
470
 
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.
471
+ # 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
472
  def write(*selected_columns)
473
473
  prepare_to_rewrite if @mode == 'r+'
474
- self.columns = @rows[0].keys if blank?(columns) && @rows[0].is_a?(::Hash) && @rows[0].keys[0].is_a?(::String)
474
+ 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
475
  write_header(*selected_columns) if header_row? && attributes
476
476
  each{|row| write_row(row, *selected_columns)}
477
477
  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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran