dsv 0.14.1 → 0.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4160107dbe47d742cbeea0e220bca705f459c5d9d7e54e385b76a29aef2e3385
4
- data.tar.gz: de2d7469e42cf0e1c5c9f5adacb40b7722d97c1dde1d10804dc2a6eb55176467
3
+ metadata.gz: b69244ec05a6f3303e048cf5f4866b026c04497cce84c1281261223f46cae932
4
+ data.tar.gz: 1f2b028014b57beed86a853ec8a36c2b0a53b3db0b0e88fcabf77645b091f329
5
5
  SHA512:
6
- metadata.gz: 6d2f8c730725c1c1b8c057c024b0263c6858c03b5f38cc21b780cdd067fbfd36759c03b078ef132cd6cae1c74022e72aecdbabd8f93c5144e3e853d637ae6ae2
7
- data.tar.gz: 617e1ce3bada65c9b89fd0a78e9e35ce1f19263f5c9e3f1136b5c808e8b9ed6dfd66bab14536d0d6e37b6a98dcd3f6c5a0930949e0f2e548e22c4e5f2115a706
6
+ metadata.gz: 9353eb0403013111353b18ec8b39c7f6c035e20b204f7c99287377f1429196b94cfa6c9fcad0dac4e8d8a1782c58ad3de65666936b95ed05a4951e6bf43a47ce
7
+ data.tar.gz: 1e1ee800d9651f883ef517cf9ac074a80e8a8731c98fec4cb05a06f65e27974b4af1ce426cf828d00926d369c88fd30f45f54c6e0e257d38ada1ff1abfabc72f
data/CHANGELOG CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## 20261126
4
4
 
5
+ 0.14.2: ~ DSV.new: A path or text no longer has its header read twice.
6
+
7
+ 1. ~ initialize(): A String source is opened by DSV::File.source or DSV::String.source, rather than taken from a DSV::File or DSV::String built and thrown away, whose own initialize had already read the header.
8
+ 2. + DSV::File.source, + DSV::String.source: Each opens its argument as an IO, and DSV::File#source and DSV::String#source call them.
9
+ 3. ~ test/dsv_test.rb: DSV.new on a path or on text is tested to construct no DSV::File or DSV::String.
10
+ 4. ~ DSV::VERSION: /0.14.1/0.14.2/
11
+
5
12
  0.14.1: ~ DSV#write: Appending (a, a+) no longer repeats the header.
6
13
 
7
14
  1. ~ write(), + writes_header?(): Under a or a+, the header is written only to an empty file. Every append had written it again, partway down a file which already had one.
data/lib/DSV/File.rb CHANGED
@@ -5,8 +5,14 @@ require_relative '../dsv'
5
5
 
6
6
  class DSV
7
7
  class File < DSV
8
+ class << self
9
+ def source(filename, options = {})
10
+ ::File.new(::File.expand_path(filename), DSV.normalised_mode(options[:mode]), options[:permissions])
11
+ end
12
+ end # class << self
13
+
8
14
  def source
9
- @source ||= ::File.new(filename, mode, permissions)
15
+ @source ||= DSV::File.source(filename, options)
10
16
  end
11
17
 
12
18
  def mode
data/lib/DSV/String.rb CHANGED
@@ -5,8 +5,15 @@ require_relative '../dsv'
5
5
 
6
6
  class DSV
7
7
  class String < DSV
8
+ class << self
9
+ # The options are taken, and unused, so that DSV#initialize calls this as it does DSV::File.source.
10
+ def source(string, options = {})
11
+ StringIO.new(string)
12
+ end
13
+ end # class << self
14
+
8
15
  def source
9
- @source ||= StringIO.new(@string)
16
+ @source ||= DSV::String.source(@string)
10
17
  end
11
18
 
12
19
  private
data/lib/DSV/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # DSV::VERSION
3
3
 
4
4
  class DSV
5
- VERSION = '0.14.1'
5
+ VERSION = '0.14.2'
6
6
  end
data/lib/dsv.rb CHANGED
@@ -331,14 +331,14 @@ class DSV
331
331
  private
332
332
 
333
333
  def initialize(source, *args)
334
+ options = DSV.extract_options(args)
334
335
  @source = (
335
336
  if source.is_a?(::String)
336
- DSV.source_type(source).new(source, *args).source
337
+ DSV.source_type(source).source(source, options)
337
338
  else
338
339
  source
339
340
  end
340
341
  )
341
- options = DSV.extract_options(args)
342
342
  @header_row = options[:header_row] || options[:headers] || options[:header] || false
343
343
  @mode = DSV.normalised_mode(options[:mode])
344
344
  @quote = options[:quote] || nil
data/test/dsv_test.rb CHANGED
@@ -365,6 +365,11 @@ describe DSV do
365
365
  _(DSV.new(StringIO.new(DATA), headers: true).read).must_equal KEYED
366
366
  end
367
367
 
368
+ it "opens a path or text itself, constructing no DSV::File or DSV::String" do
369
+ with_file{|path| _(constructions(DSV::File){DSV.new(path, headers: true).close}).must_equal 0}
370
+ _(constructions(DSV::String){DSV.new(DATA, headers: true)}).must_equal 0
371
+ end
372
+
368
373
  it "reads only the selected_columns: given at construction when a call selects none, a call's own selection winning" do
369
374
  csv = DSV.new(DATA, headers: true, selected_columns: ['a'])
370
375
  _(csv.read).must_equal [{'a' => '1'}, {'a' => '4'}]
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.14.1
4
+ version: 0.14.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran