dsv 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4914f31a3cf3aa41ed6dd8ff27b3d8b7e47910548b4d1f17dc8e6e45b5dd4722
4
- data.tar.gz: 483c3d575cbe4dab8e18c2898f7e62e594d67846d55edd984c08261e98611efb
3
+ metadata.gz: 998074c09bc9f636ccd0c0c7b6d73d78ceeda4a0efccafedcbc26c72cbec947d
4
+ data.tar.gz: 28549e92a6760f7c7ac536d1a12c886aeb7f17c920e26f4b8454e9cb5a379727
5
5
  SHA512:
6
- metadata.gz: 3af32b101d386980e623d9eced7e9e4fd882fb5185b56960888023ef72d4115e6ca669cf3199952c2f5599387826e31a3d2712250600d7a893d841580559bd2f
7
- data.tar.gz: d94eecf097300e5d1008bd62e55b6f24aeb23830bb864e572f774313b347f0efa3c0fe715a3833e2e8d439daefd849f3a9b981a63db2e3aff1f3e48b816f9f57
6
+ metadata.gz: b91d4255ea53e6a699e5f04d69d10b2cbdd5c07439c93fa755ce9c088446f9f329a419b0fd1d4a746e7582609264ede1b4ed9a8f5f6816b6115069fc13b9fa90
7
+ data.tar.gz: 87e13881fcad93d7dd7558e985ae7ef719f2f104a2eb4651192cc3a17ba9c27b99146def74b24e2ca6e3352d35ccee20507db99e9f904fc0896b078d8c01fb7a
data/CHANGELOG CHANGED
@@ -2,6 +2,26 @@
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
+
16
+ 0.16.0: + DSV.filter: An alias of DSV.select.
17
+
18
+ 1. + DSV.filter: An alias of select, as find_all is.
19
+ 2. ~ test/dsv_test.rb: Selecting by filter is tested, beside select and find_all.
20
+ 3. ~ README.md: The class-level aliases include filter.
21
+ 4. ~ TODO: The job for filter is gone, and the rest are numbered from 1.
22
+ 5. ~ ROADMAP.md: 0.16.0 is gone.
23
+ 6. ~ DSV::VERSION: /0.15.0/0.16.0/
24
+
5
25
  0.15.0: ~ DSV#read: Under :single, every field is read as single-quoted.
6
26
 
7
27
  1. ~ split_row(): Under :single, :single_quoted and :single_quotes, every field is read as single-quoted, and a row with a field which isn't raises UnquotedField. They had been read as unspecified.
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
 
@@ -73,7 +73,7 @@ DSV.detect('people.csv', headers: true){|row| row['name'] == 'Ada'}
73
73
  DSV.collect('people.csv', headers: true){|row| row['name'].upcase}
74
74
  ```
75
75
 
76
- `foreach`, `map`, `find_all` and `find` are aliases. Each closes the file it opens. Without a block, each returns an Enumerator, which opens the file again on each pass, so `DSV.each('people.csv', headers: true).each_slice(100)` works as it would on any Enumerable.
76
+ `foreach`, `map`, `find_all`, `filter` and `find` are aliases. Each closes the file it opens. Without a block, each returns an Enumerator, which opens the file again on each pass, so `DSV.each('people.csv', headers: true).each_slice(100)` works as it would on any Enumerable.
77
77
 
78
78
  ### Any delimiter
79
79
 
data/TODO CHANGED
@@ -1,17 +1,23 @@
1
1
  # TODO
2
2
 
3
- ## `filter`
3
+ ## Modes by name
4
4
 
5
- 1. filter, a class-level alias of select.
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.
6
9
 
7
- ## Modes as declarations
10
+ ## Nothing ignored
8
11
 
9
- 2. An unknown quote mode, file mode or option raises ArgumentError.
10
- 3. :unspecified, the name of the default.
11
- 4. :unquoted, the name of the mode reading no quotes, :none kept as an alias.
12
- 5. The reader chosen once, when the quote mode is set, as row_renderer is for writing.
13
- 6. .read and .open taking a path, and .parse text; a path which does not exist raising, and nothing inferred from whether a file exists.
14
- 7. attributes= setting columns, attributes always worked out from columns; rows read afterwards keyed by those names.
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
15
+
16
+ 6. attributes= setting columns, attributes always worked out from columns; rows read afterwards keyed by those names.
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.
15
21
 
16
22
  ## Streaming
17
23
 
data/lib/DSV/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # DSV::VERSION
3
3
 
4
4
  class DSV
5
- VERSION = '0.15.0'
5
+ VERSION = '0.16.1'
6
6
  end
data/lib/dsv.rb CHANGED
@@ -32,8 +32,9 @@ class DSV
32
32
  end
33
33
  end
34
34
 
35
- def source_type(source)
36
- if ::File.exist?(source)
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
@@ -71,6 +72,7 @@ class DSV
71
72
  each(source, *args).select(&block)
72
73
  end
73
74
  alias_method :find_all, :select
75
+ alias_method :filter, :select
74
76
 
75
77
  def reject(source, *args, &block)
76
78
  each(source, *args).reject(&block)
@@ -334,7 +336,7 @@ class DSV
334
336
  options = DSV.extract_options(args)
335
337
  @source = (
336
338
  if source.is_a?(::String)
337
- DSV.source_type(source).source(source, options)
339
+ DSV.source_type(source, options[:mode]).source(source, options)
338
340
  else
339
341
  source
340
342
  end
data/test/dsv_test.rb CHANGED
@@ -163,9 +163,10 @@ describe DSV do
163
163
  _(DSV.map(DATA, headers: true){|row| row['a'].to_i}).must_equal [1, 4]
164
164
  end
165
165
 
166
- it "selects the rows for which the block is true, also as find_all" do
166
+ it "selects the rows for which the block is true, also as find_all and filter" do
167
167
  _(DSV.select(DATA, headers: true){|row| row['a'] == '4'}).must_equal [KEYED.last]
168
168
  _(DSV.find_all(DATA, headers: true){|row| row['a'] == '4'}).must_equal [KEYED.last]
169
+ _(DSV.filter(DATA, headers: true){|row| row['a'] == '4'}).must_equal [KEYED.last]
169
170
  end
170
171
 
171
172
  it "rejects the rows for which the block is true" do
@@ -358,6 +359,11 @@ describe DSV do
358
359
  with_file{|path| _(DSV.source_type(path)).must_equal DSV::File}
359
360
  _(DSV.source_type(DATA)).must_equal DSV::String
360
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
361
367
  end
362
368
 
363
369
  describe ".new" do
@@ -913,12 +919,13 @@ describe DSV do
913
919
  end
914
920
  end
915
921
 
916
- it "writes a new file by name under a write mode" do
917
- skip "Decision point 4: Finding 14, a path that does not exist yet is taken as text; the note leans to a write mode making it a path"
918
- with_file do |path, directory|
919
- new_path = File.join(directory, 'new.csv')
920
- DSV.open(new_path, mode: 'w', headers: true, columns: [:a, :b], quote: :none){|csv| csv.rows = [{'a' => 1, 'b' => 2}]; csv.write}
921
- _(File.read(new_path)).must_equal "a,b\n1,2\n"
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
922
929
  end
923
930
  end
924
931
 
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.15.0
4
+ version: 0.16.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran