atv 1.0.0 → 1.1.0
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/README.md +19 -7
- data/lib/atv/version.rb +3 -1
- data/lib/atv.rb +31 -22
- metadata +49 -34
- data/.gitignore +0 -18
- data/Gemfile +0 -4
- data/Rakefile +0 -7
- data/atv.gemspec +0 -24
- data/test/atv_test.rb +0 -114
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 32b1bda3aab7e43446ace2c0667f5930b11b852f3a9fd980792e2dd81e402bd0
|
|
4
|
+
data.tar.gz: 85b5c46abc66065208d10c6926242505ea6ad5d17eb81aa73a4a1f9b2412eecb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9d837481433beaa40a775ec0829ced77d0197e2032908397214fed4657d2d2134287d09f291c6e521b746fbe8cc87017072edf72aea5d6f2cef782ea77be7264
|
|
7
|
+
data.tar.gz: ffe91ddc9029bb1907ba8a47cec763b6406f42b30301c63e4f8f0a5085e35b9b0442e625a4520d5babcdbfa9b1754fa6b9f1358feb27cf5ea7c2445f2325e3fc
|
data/README.md
CHANGED
|
@@ -27,32 +27,40 @@ or, _without_ separators, like this:
|
|
|
27
27
|
In [Ascii Tables For Clearer Testing][1] I discuss using ascii tables to improve comprehension
|
|
28
28
|
of software tests.
|
|
29
29
|
|
|
30
|
-
[1]: https://
|
|
30
|
+
[1]: https://kellyfelkins.github.io/ascii-tables-for-clearer-testing/
|
|
31
31
|
|
|
32
32
|
This gem was originally created when I worked at Indiegogo. Indiegogo has graciously transferred ownership of the
|
|
33
33
|
gem to me so that I can maintain it going forward.
|
|
34
34
|
|
|
35
|
+
## Requirements
|
|
36
|
+
|
|
37
|
+
ATV requires Ruby 3.1 or newer.
|
|
38
|
+
|
|
35
39
|
## Installation
|
|
36
40
|
|
|
37
41
|
Add this line to your application's Gemfile:
|
|
38
42
|
|
|
39
43
|
```ruby
|
|
40
|
-
gem
|
|
44
|
+
gem "atv"
|
|
41
45
|
```
|
|
42
46
|
|
|
43
47
|
And then execute:
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
```console
|
|
50
|
+
$ bundle install
|
|
51
|
+
```
|
|
46
52
|
|
|
47
|
-
Or install it
|
|
53
|
+
Or install it directly:
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
```console
|
|
56
|
+
$ gem install atv
|
|
57
|
+
```
|
|
50
58
|
|
|
51
59
|
## Usage
|
|
52
60
|
|
|
53
61
|
Rows are returned or yielded as [CSV::Row][2] objects.
|
|
54
62
|
|
|
55
|
-
[2]:
|
|
63
|
+
[2]: https://ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV/Row.html
|
|
56
64
|
|
|
57
65
|
<pre>
|
|
58
66
|
|-----------------------+------------------------------+-----------------------------------|
|
|
@@ -84,15 +92,19 @@ Rows are returned or yielded as [CSV::Row][2] objects.
|
|
|
84
92
|
**Reading a String**
|
|
85
93
|
|
|
86
94
|
```ruby
|
|
95
|
+
require "atv"
|
|
96
|
+
|
|
87
97
|
atv = ATV.from_string(string)
|
|
88
98
|
atv.each do |row|
|
|
89
99
|
# use row here...
|
|
90
100
|
end
|
|
91
101
|
```
|
|
92
102
|
|
|
93
|
-
**Reading from
|
|
103
|
+
**Reading from an IO object**
|
|
94
104
|
|
|
95
105
|
```ruby
|
|
106
|
+
require "atv"
|
|
107
|
+
|
|
96
108
|
atv = ATV.new(io)
|
|
97
109
|
atv.each do |row|
|
|
98
110
|
# use row here...
|
data/lib/atv/version.rb
CHANGED
data/lib/atv.rb
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "csv"
|
|
4
|
+
require "stringio"
|
|
5
|
+
|
|
6
|
+
require_relative "atv/version"
|
|
3
7
|
|
|
4
8
|
class ATV
|
|
5
9
|
include Enumerable
|
|
6
10
|
|
|
7
11
|
SUBSTITUTIONS = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
12
|
+
"true" => true,
|
|
13
|
+
"false" => false,
|
|
14
|
+
"null" => nil,
|
|
15
|
+
"" => nil
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
SEPARATOR_LINE_RE = /^\s*\|\-/.freeze
|
|
19
|
+
COMMENT_LINE_RE = /^\s*#/.freeze
|
|
13
20
|
|
|
14
21
|
attr_reader :headers
|
|
15
22
|
|
|
@@ -23,13 +30,14 @@ class ATV
|
|
|
23
30
|
end
|
|
24
31
|
|
|
25
32
|
def each
|
|
33
|
+
return enum_for(__method__) unless block_given?
|
|
34
|
+
|
|
26
35
|
line_data = []
|
|
27
36
|
@io.each_line do |line|
|
|
28
|
-
next if line
|
|
29
|
-
line.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
converted_folded_items = folded_items.map { |token| SUBSTITUTIONS.has_key?(token) ? SUBSTITUTIONS[token] : token }
|
|
37
|
+
next if line.match?(COMMENT_LINE_RE)
|
|
38
|
+
if (!@has_separators && !line_data.empty?) || line.match?(SEPARATOR_LINE_RE)
|
|
39
|
+
folded_items = line_data.transpose.map { |tokens| tokens.join(" ").rstrip }
|
|
40
|
+
converted_folded_items = folded_items.map { |token| SUBSTITUTIONS.fetch(token, token) }
|
|
33
41
|
csv_row = CSV::Row.new(@headers, converted_folded_items)
|
|
34
42
|
yield csv_row if csv_row.size > 0
|
|
35
43
|
line_data = []
|
|
@@ -40,27 +48,28 @@ class ATV
|
|
|
40
48
|
end
|
|
41
49
|
|
|
42
50
|
def self.from_string(string)
|
|
43
|
-
|
|
51
|
+
new(StringIO.new(string))
|
|
44
52
|
end
|
|
45
53
|
|
|
46
54
|
protected
|
|
47
55
|
|
|
48
56
|
def split_table_line(line)
|
|
57
|
+
line.strip!
|
|
49
58
|
return [] if line.empty?
|
|
50
|
-
line[1
|
|
59
|
+
line[1..].split("|").map(&:strip)
|
|
51
60
|
end
|
|
52
61
|
|
|
53
62
|
def has_separators?(io)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
@io.readline
|
|
63
|
+
3.times { io.readline }
|
|
64
|
+
|
|
57
65
|
separator_count = 0
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
io.each_line do |line|
|
|
67
|
+
next unless line.match?(SEPARATOR_LINE_RE)
|
|
68
|
+
|
|
69
|
+
separator_count += 1
|
|
70
|
+
return true if separator_count > 1
|
|
63
71
|
end
|
|
72
|
+
|
|
64
73
|
false
|
|
65
74
|
end
|
|
66
75
|
end
|
metadata
CHANGED
|
@@ -1,78 +1,95 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: atv
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kelly Felkins
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-11-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: csv
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
20
|
-
|
|
19
|
+
version: '3.0'
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '4.0'
|
|
23
|
+
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
|
-
- - "
|
|
27
|
+
- - ">="
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '3.0'
|
|
30
|
+
- - "<"
|
|
25
31
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
32
|
+
version: '4.0'
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
34
|
+
name: minitest
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
|
-
- - "
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.16'
|
|
40
|
+
- - "<"
|
|
32
41
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
42
|
+
version: '7'
|
|
34
43
|
type: :development
|
|
35
44
|
prerelease: false
|
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
46
|
requirements:
|
|
38
|
-
- - "
|
|
47
|
+
- - ">="
|
|
39
48
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
49
|
+
version: '5.16'
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '7'
|
|
41
53
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
54
|
+
name: rake
|
|
43
55
|
requirement: !ruby/object:Gem::Requirement
|
|
44
56
|
requirements:
|
|
45
|
-
- - "
|
|
57
|
+
- - ">="
|
|
46
58
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
59
|
+
version: '13.0'
|
|
60
|
+
- - "<"
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '14'
|
|
48
63
|
type: :development
|
|
49
64
|
prerelease: false
|
|
50
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
66
|
requirements:
|
|
52
|
-
- - "
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '13.0'
|
|
70
|
+
- - "<"
|
|
53
71
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
55
|
-
description: Read data from an
|
|
72
|
+
version: '14'
|
|
73
|
+
description: Read data from an ASCII table into CSV rows.
|
|
56
74
|
email:
|
|
57
75
|
- kelly@restlater.com
|
|
58
76
|
executables: []
|
|
59
77
|
extensions: []
|
|
60
78
|
extra_rdoc_files: []
|
|
61
79
|
files:
|
|
62
|
-
- ".gitignore"
|
|
63
|
-
- Gemfile
|
|
64
80
|
- LICENSE.txt
|
|
65
81
|
- README.md
|
|
66
|
-
- Rakefile
|
|
67
|
-
- atv.gemspec
|
|
68
82
|
- lib/atv.rb
|
|
69
83
|
- lib/atv/version.rb
|
|
70
|
-
- test/atv_test.rb
|
|
71
84
|
homepage: https://github.com/kellyfelkins/atv
|
|
72
85
|
licenses:
|
|
73
86
|
- MIT
|
|
74
|
-
metadata:
|
|
75
|
-
|
|
87
|
+
metadata:
|
|
88
|
+
bug_tracker_uri: https://github.com/kellyfelkins/atv/issues
|
|
89
|
+
homepage_uri: https://github.com/kellyfelkins/atv
|
|
90
|
+
rubygems_mfa_required: 'true'
|
|
91
|
+
source_code_uri: https://github.com/kellyfelkins/atv
|
|
92
|
+
post_install_message:
|
|
76
93
|
rdoc_options: []
|
|
77
94
|
require_paths:
|
|
78
95
|
- lib
|
|
@@ -80,17 +97,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
80
97
|
requirements:
|
|
81
98
|
- - ">="
|
|
82
99
|
- !ruby/object:Gem::Version
|
|
83
|
-
version: '
|
|
100
|
+
version: '3.1'
|
|
84
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
102
|
requirements:
|
|
86
103
|
- - ">="
|
|
87
104
|
- !ruby/object:Gem::Version
|
|
88
105
|
version: '0'
|
|
89
106
|
requirements: []
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
signing_key:
|
|
107
|
+
rubygems_version: 3.4.19
|
|
108
|
+
signing_key:
|
|
93
109
|
specification_version: 4
|
|
94
|
-
summary: Read
|
|
95
|
-
test_files:
|
|
96
|
-
- test/atv_test.rb
|
|
110
|
+
summary: Read ASCII table values
|
|
111
|
+
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/atv.gemspec
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# coding: utf-8
|
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require 'atv/version'
|
|
5
|
-
|
|
6
|
-
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name = "atv"
|
|
8
|
-
spec.version = Atv::VERSION
|
|
9
|
-
spec.authors = ["Kelly Felkins"]
|
|
10
|
-
spec.email = ["kelly@restlater.com"]
|
|
11
|
-
spec.summary = "Read Ascii Table Values"
|
|
12
|
-
spec.description = "Read data from an ascii table."
|
|
13
|
-
spec.homepage = "https://github.com/kellyfelkins/atv"
|
|
14
|
-
spec.license = "MIT"
|
|
15
|
-
|
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
-
spec.require_paths = ["lib"]
|
|
20
|
-
|
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.7"
|
|
22
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
|
23
|
-
spec.add_development_dependency "minitest", "~> 5.11"
|
|
24
|
-
end
|
data/test/atv_test.rb
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
require 'minitest/autorun'
|
|
2
|
-
require_relative '../lib/atv'
|
|
3
|
-
|
|
4
|
-
describe ATV do
|
|
5
|
-
describe 'with separators' do
|
|
6
|
-
before do
|
|
7
|
-
@data_as_table = <<-TEXT
|
|
8
|
-
|-----------+--------------------+--------------|
|
|
9
|
-
| name | dob | predictable? |
|
|
10
|
-
|-----------+--------------------+--------------|
|
|
11
|
-
| Malcolm | September 20, 2468 | false |
|
|
12
|
-
| Reynolds | | |
|
|
13
|
-
|-----------+--------------------+--------------|
|
|
14
|
-
| Zoe | February 15, 2484 | |
|
|
15
|
-
| Washburne | | |
|
|
16
|
-
|-----------+--------------------+--------------|
|
|
17
|
-
| Jane | | true |
|
|
18
|
-
|-----------+--------------------+--------------|
|
|
19
|
-
# | Inara | October 14, 2489 | |
|
|
20
|
-
# | Sara | | |
|
|
21
|
-
# |-----------+--------------------+--------------|
|
|
22
|
-
| Derrial | null | true |
|
|
23
|
-
| Book | | |
|
|
24
|
-
|-----------+--------------------+--------------|
|
|
25
|
-
TEXT
|
|
26
|
-
@expected = [
|
|
27
|
-
['Malcolm Reynolds', 'September 20, 2468', false],
|
|
28
|
-
['Zoe Washburne', 'February 15, 2484', nil],
|
|
29
|
-
['Jane', nil, true],
|
|
30
|
-
['Derrial Book', nil, true]
|
|
31
|
-
]
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
describe '#each' do
|
|
35
|
-
before do
|
|
36
|
-
@atv = ATV.new(StringIO.new(@data_as_table))
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'with a block it yields rows of data as CSV rows and ignores commented lines' do
|
|
40
|
-
i = 0
|
|
41
|
-
|
|
42
|
-
@atv.each do |row|
|
|
43
|
-
row.fields.must_equal(@expected[i])
|
|
44
|
-
row[0].must_equal(@expected[i][0])
|
|
45
|
-
row['name'].must_equal(@expected[i][0])
|
|
46
|
-
row[1].must_equal(@expected[i][1])
|
|
47
|
-
row['dob'].must_equal(@expected[i][1])
|
|
48
|
-
row[2].must_equal(@expected[i][2])
|
|
49
|
-
row['predictable?'].must_equal(@expected[i][2])
|
|
50
|
-
i += 1
|
|
51
|
-
end
|
|
52
|
-
i.must_equal(4)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'without a block it returns an enumerator of data as CSV rows' do
|
|
56
|
-
enum = @atv.enum_for
|
|
57
|
-
enum.map(&:fields).must_equal(@expected)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
describe "#headers" do
|
|
62
|
-
it 'returns all the headers' do
|
|
63
|
-
ATV.new(StringIO.new(@data_as_table)).headers.must_equal(%w|name dob predictable?|)
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
describe ".from_string(string)" do
|
|
68
|
-
it 'initializes ATV with an IO object' do
|
|
69
|
-
fussy = -> (io) { io.must_be_kind_of StringIO }
|
|
70
|
-
|
|
71
|
-
ATV.stub :new, fussy do
|
|
72
|
-
ATV.from_string(@data_as_table)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
describe 'without separators' do
|
|
79
|
-
describe '#each' do
|
|
80
|
-
it 'with a block it yields rows of data as CSV rows' do
|
|
81
|
-
data_as_table = <<-TEXT
|
|
82
|
-
|-----------+--------------------+--------------|
|
|
83
|
-
| name | dob | predictable? |
|
|
84
|
-
|-----------+--------------------+--------------|
|
|
85
|
-
| Malcolm | September 20, 2468 | false |
|
|
86
|
-
| Zoe | February 15, 2484 | |
|
|
87
|
-
| Derrial | null | true |
|
|
88
|
-
|-----------+--------------------+--------------|
|
|
89
|
-
TEXT
|
|
90
|
-
|
|
91
|
-
expected = [
|
|
92
|
-
['Malcolm', 'September 20, 2468', false],
|
|
93
|
-
['Zoe', 'February 15, 2484', nil],
|
|
94
|
-
['Derrial', nil, true]
|
|
95
|
-
]
|
|
96
|
-
@atv = ATV.new(StringIO.new(data_as_table))
|
|
97
|
-
|
|
98
|
-
i = 0
|
|
99
|
-
|
|
100
|
-
@atv.each do |row|
|
|
101
|
-
row.fields.must_equal(expected[i])
|
|
102
|
-
row[0].must_equal(expected[i][0])
|
|
103
|
-
row['name'].must_equal(expected[i][0])
|
|
104
|
-
row[1].must_equal(expected[i][1])
|
|
105
|
-
row['dob'].must_equal(expected[i][1])
|
|
106
|
-
row[2].must_equal(expected[i][2])
|
|
107
|
-
row['predictable?'].must_equal(expected[i][2])
|
|
108
|
-
i += 1
|
|
109
|
-
end
|
|
110
|
-
i.must_equal(3)
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|