atv 1.0.1 → 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 +29 -23
- 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 -227
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,18 +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
|
|
13
17
|
|
|
14
|
-
SEPARATOR_LINE_RE = /^\s
|
|
15
|
-
COMMENT_LINE_RE = /^\s
|
|
18
|
+
SEPARATOR_LINE_RE = /^\s*\|\-/.freeze
|
|
19
|
+
COMMENT_LINE_RE = /^\s*#/.freeze
|
|
16
20
|
|
|
17
21
|
attr_reader :headers
|
|
18
22
|
|
|
@@ -26,12 +30,14 @@ class ATV
|
|
|
26
30
|
end
|
|
27
31
|
|
|
28
32
|
def each
|
|
33
|
+
return enum_for(__method__) unless block_given?
|
|
34
|
+
|
|
29
35
|
line_data = []
|
|
30
36
|
@io.each_line do |line|
|
|
31
|
-
next if line
|
|
32
|
-
if (!@has_separators && !line_data.empty?) || line
|
|
33
|
-
folded_items = line_data.transpose.map { |tokens| tokens.join(
|
|
34
|
-
converted_folded_items = folded_items.map { |token| SUBSTITUTIONS.
|
|
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) }
|
|
35
41
|
csv_row = CSV::Row.new(@headers, converted_folded_items)
|
|
36
42
|
yield csv_row if csv_row.size > 0
|
|
37
43
|
line_data = []
|
|
@@ -42,7 +48,7 @@ class ATV
|
|
|
42
48
|
end
|
|
43
49
|
|
|
44
50
|
def self.from_string(string)
|
|
45
|
-
|
|
51
|
+
new(StringIO.new(string))
|
|
46
52
|
end
|
|
47
53
|
|
|
48
54
|
protected
|
|
@@ -50,20 +56,20 @@ class ATV
|
|
|
50
56
|
def split_table_line(line)
|
|
51
57
|
line.strip!
|
|
52
58
|
return [] if line.empty?
|
|
53
|
-
line[1
|
|
59
|
+
line[1..].split("|").map(&:strip)
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
def has_separators?(io)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
@io.readline
|
|
63
|
+
3.times { io.readline }
|
|
64
|
+
|
|
60
65
|
separator_count = 0
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
66
71
|
end
|
|
72
|
+
|
|
67
73
|
false
|
|
68
74
|
end
|
|
69
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.0
|
|
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"
|
|
24
|
-
end
|
data/test/atv_test.rb
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
require 'minitest/autorun'
|
|
2
|
-
require_relative '../lib/atv'
|
|
3
|
-
|
|
4
|
-
describe ATV do
|
|
5
|
-
describe 'with separators' do
|
|
6
|
-
describe '#each' do
|
|
7
|
-
it 'with a block it yields rows of data as CSV rows and ignores commented lines' do
|
|
8
|
-
data_as_table = <<-TEXT
|
|
9
|
-
|-----------+--------------------+--------------|
|
|
10
|
-
| name | dob | predictable? |
|
|
11
|
-
|-----------+--------------------+--------------|
|
|
12
|
-
| Malcolm | September 20, 2468 | false |
|
|
13
|
-
| Reynolds | | |
|
|
14
|
-
|-----------+--------------------+--------------|
|
|
15
|
-
| Zoe | February 15, 2484 | |
|
|
16
|
-
| Washburne | | |
|
|
17
|
-
|-----------+--------------------+--------------|
|
|
18
|
-
| Jane | | true |
|
|
19
|
-
|-----------+--------------------+--------------|
|
|
20
|
-
# | Inara | October 14, 2489 | |
|
|
21
|
-
# | Sara | | |
|
|
22
|
-
# |-----------+--------------------+--------------|
|
|
23
|
-
| Derrial | null | true |
|
|
24
|
-
| Book | | |
|
|
25
|
-
|-----------+--------------------+--------------|
|
|
26
|
-
TEXT
|
|
27
|
-
|
|
28
|
-
expected = [
|
|
29
|
-
['Malcolm Reynolds', 'September 20, 2468', false],
|
|
30
|
-
['Zoe Washburne', 'February 15, 2484', nil],
|
|
31
|
-
['Jane', nil, true],
|
|
32
|
-
['Derrial Book', nil, true]
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
i = 0
|
|
36
|
-
|
|
37
|
-
ATV.new(StringIO.new(data_as_table)).each do |row|
|
|
38
|
-
row.fields.must_equal(expected[i])
|
|
39
|
-
row[0].must_equal(expected[i][0])
|
|
40
|
-
row['name'].must_equal(expected[i][0])
|
|
41
|
-
row[1].must_equal(expected[i][1])
|
|
42
|
-
row['dob'].must_equal(expected[i][1])
|
|
43
|
-
row[2].must_equal(expected[i][2])
|
|
44
|
-
row['predictable?'].must_equal(expected[i][2])
|
|
45
|
-
i += 1
|
|
46
|
-
end
|
|
47
|
-
i.must_equal(4)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'without a block it returns an enumerator of data as CSV rows' do
|
|
51
|
-
data_as_table = <<-TEXT
|
|
52
|
-
|-----------+--------------------+--------------|
|
|
53
|
-
| name | dob | predictable? |
|
|
54
|
-
|-----------+--------------------+--------------|
|
|
55
|
-
| Malcolm | September 20, 2468 | false |
|
|
56
|
-
| Reynolds | | |
|
|
57
|
-
|-----------+--------------------+--------------|
|
|
58
|
-
| Zoe | February 15, 2484 | |
|
|
59
|
-
| Washburne | | |
|
|
60
|
-
|-----------+--------------------+--------------|
|
|
61
|
-
TEXT
|
|
62
|
-
|
|
63
|
-
expected = [
|
|
64
|
-
['Malcolm Reynolds', 'September 20, 2468', false],
|
|
65
|
-
['Zoe Washburne', 'February 15, 2484', nil],
|
|
66
|
-
]
|
|
67
|
-
|
|
68
|
-
atv = ATV.new(StringIO.new(data_as_table))
|
|
69
|
-
enum = atv.enum_for
|
|
70
|
-
enum.map(&:fields).must_equal(expected)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe "#headers" do
|
|
75
|
-
it 'returns all the headers' do
|
|
76
|
-
data_as_table = <<-TEXT
|
|
77
|
-
|-----------+--------------------+--------------|
|
|
78
|
-
| name | dob | predictable? |
|
|
79
|
-
|-----------+--------------------+--------------|
|
|
80
|
-
| Malcolm | September 20, 2468 | false |
|
|
81
|
-
| Reynolds | | |
|
|
82
|
-
|-----------+--------------------+--------------|
|
|
83
|
-
| Zoe | February 15, 2484 | |
|
|
84
|
-
| Washburne | | |
|
|
85
|
-
|-----------+--------------------+--------------|
|
|
86
|
-
TEXT
|
|
87
|
-
ATV.new(StringIO.new(data_as_table)).headers.must_equal(%w|name dob predictable?|)
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
describe ".from_string(string)" do
|
|
92
|
-
it 'initializes ATV with an IO object' do
|
|
93
|
-
data_as_table = <<-TEXT
|
|
94
|
-
|-----------+--------------------+--------------|
|
|
95
|
-
| name | dob | predictable? |
|
|
96
|
-
|-----------+--------------------+--------------|
|
|
97
|
-
| Malcolm | September 20, 2468 | false |
|
|
98
|
-
| Reynolds | | |
|
|
99
|
-
|-----------+--------------------+--------------|
|
|
100
|
-
| Zoe | February 15, 2484 | |
|
|
101
|
-
| Washburne | | |
|
|
102
|
-
|-----------+--------------------+--------------|
|
|
103
|
-
TEXT
|
|
104
|
-
|
|
105
|
-
fussy = -> (io) { io.must_be_kind_of StringIO }
|
|
106
|
-
|
|
107
|
-
ATV.stub :new, fussy do
|
|
108
|
-
ATV.from_string(data_as_table)
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
describe 'with separators, indented' do
|
|
115
|
-
describe '#each' do
|
|
116
|
-
it 'with a block it yields rows of data as CSV rows' do
|
|
117
|
-
data_as_table = <<TEXT
|
|
118
|
-
|-----------+--------------------+--------------|
|
|
119
|
-
| name | dob | predictable? |
|
|
120
|
-
|-----------+--------------------+--------------|
|
|
121
|
-
| Malcolm | September 20, 2468 | false |
|
|
122
|
-
| Reynolds | | |
|
|
123
|
-
|-----------+--------------------+--------------|
|
|
124
|
-
| Zoe | February 15, 2484 | |
|
|
125
|
-
| Washburne | | |
|
|
126
|
-
|-----------+--------------------+--------------|
|
|
127
|
-
TEXT
|
|
128
|
-
|
|
129
|
-
expected = [
|
|
130
|
-
['Malcolm Reynolds', 'September 20, 2468', false],
|
|
131
|
-
['Zoe Washburne', 'February 15, 2484', nil],
|
|
132
|
-
]
|
|
133
|
-
|
|
134
|
-
atv = ATV.new(StringIO.new(data_as_table))
|
|
135
|
-
|
|
136
|
-
i = 0
|
|
137
|
-
|
|
138
|
-
atv.each do |row|
|
|
139
|
-
row.fields.must_equal(expected[i])
|
|
140
|
-
row[0].must_equal(expected[i][0])
|
|
141
|
-
row['name'].must_equal(expected[i][0])
|
|
142
|
-
row[1].must_equal(expected[i][1])
|
|
143
|
-
row['dob'].must_equal(expected[i][1])
|
|
144
|
-
row[2].must_equal(expected[i][2])
|
|
145
|
-
row['predictable?'].must_equal(expected[i][2])
|
|
146
|
-
i += 1
|
|
147
|
-
end
|
|
148
|
-
i.must_equal(2)
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
describe 'without separators' do
|
|
154
|
-
describe '#each' do
|
|
155
|
-
it 'with a block it yields rows of data as CSV rows' do
|
|
156
|
-
data_as_table = <<-TEXT
|
|
157
|
-
|-----------+--------------------+--------------|
|
|
158
|
-
| name | dob | predictable? |
|
|
159
|
-
|-----------+--------------------+--------------|
|
|
160
|
-
| Malcolm | September 20, 2468 | false |
|
|
161
|
-
| Zoe | February 15, 2484 | |
|
|
162
|
-
| Derrial | null | true |
|
|
163
|
-
|-----------+--------------------+--------------|
|
|
164
|
-
TEXT
|
|
165
|
-
|
|
166
|
-
expected = [
|
|
167
|
-
['Malcolm', 'September 20, 2468', false],
|
|
168
|
-
['Zoe', 'February 15, 2484', nil],
|
|
169
|
-
['Derrial', nil, true]
|
|
170
|
-
]
|
|
171
|
-
|
|
172
|
-
atv = ATV.new(StringIO.new(data_as_table))
|
|
173
|
-
|
|
174
|
-
i = 0
|
|
175
|
-
|
|
176
|
-
atv.each do |row|
|
|
177
|
-
row.fields.must_equal(expected[i])
|
|
178
|
-
row[0].must_equal(expected[i][0])
|
|
179
|
-
row['name'].must_equal(expected[i][0])
|
|
180
|
-
row[1].must_equal(expected[i][1])
|
|
181
|
-
row['dob'].must_equal(expected[i][1])
|
|
182
|
-
row[2].must_equal(expected[i][2])
|
|
183
|
-
row['predictable?'].must_equal(expected[i][2])
|
|
184
|
-
i += 1
|
|
185
|
-
end
|
|
186
|
-
i.must_equal(3)
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
describe 'without separators, indented' do
|
|
192
|
-
describe '#each' do
|
|
193
|
-
it 'with a block it yields rows of data as CSV rows' do
|
|
194
|
-
data_as_table = <<TEXT
|
|
195
|
-
|-----------+--------------------+--------------|
|
|
196
|
-
| name | dob | predictable? |
|
|
197
|
-
|-----------+--------------------+--------------|
|
|
198
|
-
| Malcolm | September 20, 2468 | false |
|
|
199
|
-
| Zoe | February 15, 2484 | |
|
|
200
|
-
| Derrial | null | true |
|
|
201
|
-
|-----------+--------------------+--------------|
|
|
202
|
-
TEXT
|
|
203
|
-
|
|
204
|
-
expected = [
|
|
205
|
-
['Malcolm', 'September 20, 2468', false],
|
|
206
|
-
['Zoe', 'February 15, 2484', nil],
|
|
207
|
-
['Derrial', nil, true]
|
|
208
|
-
]
|
|
209
|
-
atv = ATV.new(StringIO.new(data_as_table))
|
|
210
|
-
|
|
211
|
-
i = 0
|
|
212
|
-
|
|
213
|
-
atv.each do |row|
|
|
214
|
-
row.fields.must_equal(expected[i])
|
|
215
|
-
row[0].must_equal(expected[i][0])
|
|
216
|
-
row['name'].must_equal(expected[i][0])
|
|
217
|
-
row[1].must_equal(expected[i][1])
|
|
218
|
-
row['dob'].must_equal(expected[i][1])
|
|
219
|
-
row[2].must_equal(expected[i][2])
|
|
220
|
-
row['predictable?'].must_equal(expected[i][2])
|
|
221
|
-
i += 1
|
|
222
|
-
end
|
|
223
|
-
i.must_equal(3)
|
|
224
|
-
end
|
|
225
|
-
end
|
|
226
|
-
end
|
|
227
|
-
end
|