atv 0.1.0 → 1.0.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 +2 -2
- data/lib/atv.rb +5 -6
- data/lib/atv/version.rb +1 -1
- data/test/atv_test.rb +6 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01241ccb91e5d82a64f6ea850637960f09ae9a311cf2c246776df57e04373df5
|
4
|
+
data.tar.gz: 5a04b4843e859ea00808415f876b966cd30ed4eb9330429bb2846b034e07ec1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41f03eb6c3e36e1925c7dca47652ca96d3729ffbb20854219ccd28b8a55f2b1c5c9021978ac0f2290c4492dfa927a24a43414486dd2b0f0a8046831b7b0c7d19
|
7
|
+
data.tar.gz: dadd30ee857e755648608d7240ab8fd03d1333a56cdfb2b3623eabd09591d89286f7d04e05be7e230ef1b0b33043ddfb45925a534443bf9d2e3e7d73c3caa3b0
|
data/README.md
CHANGED
@@ -66,8 +66,8 @@ Rows are returned or yielded as [CSV::Row][2] objects.
|
|
66
66
|
| folded | | strings are folded with a single |
|
67
67
|
| | | space replacing the new line |
|
68
68
|
|-----------------------+------------------------------+-----------------------------------|
|
69
|
-
| |
|
70
|
-
| | |
|
69
|
+
| | nil | The CSV::Row object will have nil |
|
70
|
+
| | | for blank values |
|
71
71
|
|-----------------------+------------------------------+-----------------------------------|
|
72
72
|
| null | nil | null, true, and false are |
|
73
73
|
| | | special values |
|
data/lib/atv.rb
CHANGED
@@ -7,7 +7,8 @@ class ATV
|
|
7
7
|
SUBSTITUTIONS = {
|
8
8
|
'true' => true,
|
9
9
|
'false' => false,
|
10
|
-
'null' => nil
|
10
|
+
'null' => nil,
|
11
|
+
'' => nil
|
11
12
|
}
|
12
13
|
|
13
14
|
attr_reader :headers
|
@@ -27,11 +28,9 @@ class ATV
|
|
27
28
|
next if line =~ /^\s*#/
|
28
29
|
line.chomp!
|
29
30
|
if (!@has_separators && !line_data.empty?) || line =~ /^\|\-/
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
map { |token| SUBSTITUTIONS.has_key?(token) ? SUBSTITUTIONS[token] : token }
|
34
|
-
).delete_if {|k, v| v == ''}
|
31
|
+
folded_items = line_data.transpose.map { |tokens| tokens.join(' ').rstrip }
|
32
|
+
converted_folded_items = folded_items.map { |token| SUBSTITUTIONS.has_key?(token) ? SUBSTITUTIONS[token] : token }
|
33
|
+
csv_row = CSV::Row.new(@headers, converted_folded_items)
|
35
34
|
yield csv_row if csv_row.size > 0
|
36
35
|
line_data = []
|
37
36
|
next if @has_separators
|
data/lib/atv/version.rb
CHANGED
data/test/atv_test.rb
CHANGED
@@ -14,6 +14,8 @@ describe ATV do
|
|
14
14
|
| Zoe | February 15, 2484 | |
|
15
15
|
| Washburne | | |
|
16
16
|
|-----------+--------------------+--------------|
|
17
|
+
| Jane | | true |
|
18
|
+
|-----------+--------------------+--------------|
|
17
19
|
# | Inara | October 14, 2489 | |
|
18
20
|
# | Sara | | |
|
19
21
|
# |-----------+--------------------+--------------|
|
@@ -23,7 +25,8 @@ describe ATV do
|
|
23
25
|
TEXT
|
24
26
|
@expected = [
|
25
27
|
['Malcolm Reynolds', 'September 20, 2468', false],
|
26
|
-
['Zoe Washburne', 'February 15, 2484'],
|
28
|
+
['Zoe Washburne', 'February 15, 2484', nil],
|
29
|
+
['Jane', nil, true],
|
27
30
|
['Derrial Book', nil, true]
|
28
31
|
]
|
29
32
|
end
|
@@ -46,7 +49,7 @@ describe ATV do
|
|
46
49
|
row['predictable?'].must_equal(@expected[i][2])
|
47
50
|
i += 1
|
48
51
|
end
|
49
|
-
i.must_equal(
|
52
|
+
i.must_equal(4)
|
50
53
|
end
|
51
54
|
|
52
55
|
it 'without a block it returns an enumerator of data as CSV rows' do
|
@@ -87,7 +90,7 @@ describe ATV do
|
|
87
90
|
|
88
91
|
expected = [
|
89
92
|
['Malcolm', 'September 20, 2468', false],
|
90
|
-
['Zoe', 'February 15, 2484'],
|
93
|
+
['Zoe', 'February 15, 2484', nil],
|
91
94
|
['Derrial', nil, true]
|
92
95
|
]
|
93
96
|
@atv = ATV.new(StringIO.new(data_as_table))
|