atv 0.0.7 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +2 -0
- data/README.md +19 -3
- data/Rakefile +5 -0
- data/lib/atv.rb +19 -3
- data/lib/atv/version.rb +1 -1
- data/test/atv_test.rb +75 -36
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YWFjMTdhOGQ3NDQyMmRlZmFhNjZiOWVlODllY2JlMmNiNzU3ZmMxOQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b74da012d7232aae6f86f45060bd5d31adeb61a8
|
4
|
+
data.tar.gz: 8c5f5a6d427d2f6c480f890cd7702e53fcb8bfdc
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NGYyNmU3ZWZjYTIyMDEzNGQ1MTE2Y2FmZjNkMzkwOGQxNDUyNGZkNGViNTA0
|
11
|
-
M2Q3MGFkOWQwMjQ5MjE1Zjc1OTlkODU3NzUwODk0MGQ3Y2RjM2U=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NmE0MzY2ZDQ3ODkzY2EwMjU1ZGI2ODU2YjMxY2MxYTJjZjFkOWI2NTVjMjhj
|
14
|
-
OWVhZDRkYzUwZWZlNDljYjdhMWViMmMxMjQ0ODViZWZiNTcxZGVhYmJhZDc0
|
15
|
-
NDU2ZWMzZWFmYjU2ZjRhMjRiYWY3ZDdlZDVkMGZlNDQ5MDFkNmI=
|
6
|
+
metadata.gz: bb77ad58f596a342344c223a467e9de184778e3af9f7ba81a611cbf0cb7fdeb9d22cd104fa541468b7998905b8f9412a28a979753144a93e305d4c67f7af3f6e
|
7
|
+
data.tar.gz: e71e57a0ffd7700b87561a17573c33d850fdc405f648231bd836031d85e33c02b990bab47b6b0a6aba0ff12f21bb264e6f9bc81d2ff2a0b1e3731824a298b7a2
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -13,6 +13,22 @@ It allows you to read data formatted like this:
|
|
13
13
|
|------------------+--------------------|
|
14
14
|
</pre>
|
15
15
|
|
16
|
+
or, without separators, like this:
|
17
|
+
|
18
|
+
<pre>
|
19
|
+
|------------------+--------------------|
|
20
|
+
| name | dob |
|
21
|
+
|------------------+--------------------|
|
22
|
+
| Malcolm Reynolds | September 20, 2468 |
|
23
|
+
| Zoe Washburne | February 15, 2484 |
|
24
|
+
|------------------+--------------------|
|
25
|
+
</pre>
|
26
|
+
|
27
|
+
In [Ascii Tables For Clearer Testing][1] I discuss using ascii tables to improve comprehension
|
28
|
+
of software tests.
|
29
|
+
|
30
|
+
[1]: http://technology.indiegogo.com/2015/01/ascii-tables-for-clearer-testing/
|
31
|
+
|
16
32
|
## Installation
|
17
33
|
|
18
34
|
Add this line to your application's Gemfile:
|
@@ -31,7 +47,9 @@ Or install it yourself as:
|
|
31
47
|
|
32
48
|
## Usage
|
33
49
|
|
34
|
-
Rows are returned or yielded as [CSV::Row][
|
50
|
+
Rows are returned or yielded as [CSV::Row][2] objects.
|
51
|
+
|
52
|
+
[2]: http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV/Row.html
|
35
53
|
|
36
54
|
<pre>
|
37
55
|
|-----------------------+------------------------------+-----------------------------------|
|
@@ -82,5 +100,3 @@ end
|
|
82
100
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
83
101
|
4. Push to the branch (`git push origin my-new-feature`)
|
84
102
|
5. Create a new Pull Request
|
85
|
-
|
86
|
-
[1]: http://www.ruby-doc.org/stdlib/libdoc/csv/rdoc/CSV/Row.html
|
data/Rakefile
CHANGED
data/lib/atv.rb
CHANGED
@@ -10,10 +10,12 @@ class ATV
|
|
10
10
|
'null' => nil
|
11
11
|
}
|
12
12
|
|
13
|
-
attr_reader
|
13
|
+
attr_reader :headers
|
14
14
|
|
15
15
|
def initialize(io)
|
16
16
|
@io = io
|
17
|
+
@has_separators = has_separators?(@io)
|
18
|
+
@io.rewind
|
17
19
|
@io.readline
|
18
20
|
@headers = split_table_line(@io.readline.chomp)
|
19
21
|
@io.readline
|
@@ -23,7 +25,7 @@ class ATV
|
|
23
25
|
line_data = []
|
24
26
|
@io.each_line do |line|
|
25
27
|
line.chomp!
|
26
|
-
if line =~ /^\|\-/
|
28
|
+
if (!@has_separators && !line_data.empty?) || line =~ /^\|\-/
|
27
29
|
csv_row = CSV::Row.new(@headers, line_data.
|
28
30
|
transpose.
|
29
31
|
map { |tokens| tokens.reject(&:empty?).join(' ') }.
|
@@ -31,7 +33,7 @@ class ATV
|
|
31
33
|
).delete_if {|k, v| v == ''}
|
32
34
|
yield csv_row if csv_row.size > 0
|
33
35
|
line_data = []
|
34
|
-
next
|
36
|
+
next if @has_separators
|
35
37
|
end
|
36
38
|
line_data << split_table_line(line)
|
37
39
|
end
|
@@ -47,4 +49,18 @@ class ATV
|
|
47
49
|
return [] if line.empty?
|
48
50
|
line[1..-1].split('|').map(&:strip)
|
49
51
|
end
|
52
|
+
|
53
|
+
def has_separators?(io)
|
54
|
+
@io.readline
|
55
|
+
@io.readline
|
56
|
+
@io.readline
|
57
|
+
separator_count = 0
|
58
|
+
@io.each_line do |line|
|
59
|
+
if line =~ /^\|\-/
|
60
|
+
separator_count += 1
|
61
|
+
return true if separator_count > 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
false
|
65
|
+
end
|
50
66
|
end
|
data/lib/atv/version.rb
CHANGED
data/test/atv_test.rb
CHANGED
@@ -2,7 +2,9 @@ require 'minitest/autorun'
|
|
2
2
|
require_relative '../lib/atv'
|
3
3
|
|
4
4
|
describe ATV do
|
5
|
-
|
5
|
+
describe 'with separators' do
|
6
|
+
before do
|
7
|
+
@data_as_table = <<-TEXT
|
6
8
|
|-----------+--------------------+--------------|
|
7
9
|
| name | dob | predictable? |
|
8
10
|
|-----------+--------------------+--------------|
|
@@ -15,54 +17,91 @@ describe ATV do
|
|
15
17
|
| Derrial | null | true |
|
16
18
|
| Book | | |
|
17
19
|
|-----------+--------------------+--------------|
|
20
|
+
TEXT
|
21
|
+
@expected = [
|
22
|
+
['Malcolm Reynolds', 'September 20, 2468', false],
|
23
|
+
['Zoe Washburne', 'February 15, 2484'],
|
24
|
+
['Derrial Book', nil, true]
|
25
|
+
]
|
26
|
+
end
|
18
27
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
['Zoe Washburne', 'February 15, 2484'],
|
24
|
-
['Derrial Book', nil, true]
|
25
|
-
]
|
28
|
+
describe '#each' do
|
29
|
+
before do
|
30
|
+
@atv = ATV.new(StringIO.new(@data_as_table))
|
31
|
+
end
|
26
32
|
|
27
|
-
|
28
|
-
|
29
|
-
@atv = ATV.new(StringIO.new(DATA_AS_TABLE))
|
30
|
-
end
|
33
|
+
it 'with a block it yields rows of data as CSV rows' do
|
34
|
+
i = 0
|
31
35
|
|
32
|
-
|
33
|
-
|
36
|
+
@atv.each do |row|
|
37
|
+
row.fields.must_equal(@expected[i])
|
38
|
+
row[0].must_equal(@expected[i][0])
|
39
|
+
row['name'].must_equal(@expected[i][0])
|
40
|
+
row[1].must_equal(@expected[i][1])
|
41
|
+
row['dob'].must_equal(@expected[i][1])
|
42
|
+
row[2].must_equal(@expected[i][2])
|
43
|
+
row['predictable?'].must_equal(@expected[i][2])
|
44
|
+
i += 1
|
45
|
+
end
|
46
|
+
i.must_equal(3)
|
47
|
+
end
|
34
48
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
row['name'].must_equal(EXPECTED[i][0])
|
39
|
-
row[1].must_equal(EXPECTED[i][1])
|
40
|
-
row['dob'].must_equal(EXPECTED[i][1])
|
41
|
-
row[2].must_equal(EXPECTED[i][2])
|
42
|
-
row['predictable?'].must_equal(EXPECTED[i][2])
|
43
|
-
i += 1
|
49
|
+
it 'without a block it returns an enumerator of data as CSV rows' do
|
50
|
+
enum = @atv.enum_for
|
51
|
+
enum.map(&:fields).must_equal(@expected)
|
44
52
|
end
|
45
|
-
i.must_equal(3)
|
46
53
|
end
|
47
54
|
|
48
|
-
|
49
|
-
|
50
|
-
|
55
|
+
describe "#headers" do
|
56
|
+
it 'returns all the headers' do
|
57
|
+
ATV.new(StringIO.new(@data_as_table)).headers.must_equal(%w|name dob predictable?|)
|
58
|
+
end
|
51
59
|
end
|
52
|
-
end
|
53
60
|
|
54
|
-
|
55
|
-
|
56
|
-
|
61
|
+
describe ".from_string(string)" do
|
62
|
+
it 'initializes ATV with an IO object' do
|
63
|
+
fussy = -> (io) { io.must_be_kind_of StringIO }
|
64
|
+
|
65
|
+
ATV.stub :new, fussy do
|
66
|
+
ATV.from_string(@data_as_table)
|
67
|
+
end
|
68
|
+
end
|
57
69
|
end
|
58
70
|
end
|
59
71
|
|
60
|
-
describe
|
61
|
-
|
62
|
-
|
72
|
+
describe 'without separators' do
|
73
|
+
describe '#each' do
|
74
|
+
it 'with a block it yields rows of data as CSV rows' do
|
75
|
+
data_as_table = <<-TEXT
|
76
|
+
|-----------+--------------------+--------------|
|
77
|
+
| name | dob | predictable? |
|
78
|
+
|-----------+--------------------+--------------|
|
79
|
+
| Malcolm | September 20, 2468 | false |
|
80
|
+
| Zoe | February 15, 2484 | |
|
81
|
+
| Derrial | null | true |
|
82
|
+
|-----------+--------------------+--------------|
|
83
|
+
TEXT
|
84
|
+
|
85
|
+
expected = [
|
86
|
+
['Malcolm', 'September 20, 2468', false],
|
87
|
+
['Zoe', 'February 15, 2484'],
|
88
|
+
['Derrial', nil, true]
|
89
|
+
]
|
90
|
+
@atv = ATV.new(StringIO.new(data_as_table))
|
91
|
+
|
92
|
+
i = 0
|
63
93
|
|
64
|
-
|
65
|
-
|
94
|
+
@atv.each do |row|
|
95
|
+
row.fields.must_equal(expected[i])
|
96
|
+
row[0].must_equal(expected[i][0])
|
97
|
+
row['name'].must_equal(expected[i][0])
|
98
|
+
row[1].must_equal(expected[i][1])
|
99
|
+
row['dob'].must_equal(expected[i][1])
|
100
|
+
row[2].must_equal(expected[i][2])
|
101
|
+
row['predictable?'].must_equal(expected[i][2])
|
102
|
+
i += 1
|
103
|
+
end
|
104
|
+
i.must_equal(3)
|
66
105
|
end
|
67
106
|
end
|
68
107
|
end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Felkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: Read data from an ascii table.
|
@@ -45,7 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
51
|
- README.md
|
@@ -64,17 +64,17 @@ require_paths:
|
|
64
64
|
- lib
|
65
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.
|
77
|
+
rubygems_version: 2.4.8
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Read Ascii Table Values
|