array-formatter 1.0.1 → 1.0.2
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/lib/array/formatter.rb +1 -1
- data/lib/array/formatter/version.rb +1 -1
- data/test/ref/a-ascii.txt +9 -0
- data/test/ref/a-csv.txt +4 -0
- data/test/ref/a-html.txt +4 -0
- data/test/ref/a-unicode.txt +9 -0
- data/test/ref/a-unicode_single.txt +9 -0
- data/test/ref/b-ascii.txt +17 -0
- data/test/ref/b-csv.txt +8 -0
- data/test/ref/b-html.txt +42 -0
- data/test/ref/b-unicode.txt +17 -0
- data/test/ref/b-unicode_double.txt +17 -0
- data/test/ref/b-unicode_mixed.txt +17 -0
- data/test/test-array-formatter.rb +100 -12
- metadata +24 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a0c26f92c099a6b15e0450106bf4b5da11362de
|
|
4
|
+
data.tar.gz: df94ab3f2a7191cd083a616ac33ee239b41e5763
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c8a41e02bc22a6371314d43b3aca87d5a812d3dca35b5333f5feb217f3b0dd9c92dab41115e94d5cc48da3d66e4e34c64e54e256ef0a4d8c0644705be46cf852
|
|
7
|
+
data.tar.gz: cf129546e5260206d19b9e08ac07390be4ce41c0526fd5fd7142770cc55a62a8622cfe4e4e74daf176d6e96098e628058c03b1caec762fcd96650c6f8d3e0e4a
|
data/lib/array/formatter.rb
CHANGED
|
@@ -154,7 +154,7 @@ class Array
|
|
|
154
154
|
# :unicode_mixed - a table with double outer lines, and single inner lines
|
|
155
155
|
TableChars.new :unicode_mixed, [ "\u2554", "\u2550", "\u2564", "\u2557", # tlb, tb, tib, trb
|
|
156
156
|
"\u2551", "\u2502", "\u2551", # ldb, idb, rdb
|
|
157
|
-
"\
|
|
157
|
+
"\u255F", "\u2500", "\u253C", "\u2562", # lib, ib, mib, rib
|
|
158
158
|
"\u255A", "\u2550", "\u2567", "\u255D" ] # blb, bb, bib, brb
|
|
159
159
|
|
|
160
160
|
TableChars.new :dos_single, [ "\xDA", "\xC4", "\xC2", "\xBF", # tlb, tb, tib, trb
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
+-------------+--------------+--------------------+-------------+------------------+
|
|
2
|
+
| Company | Name | Address | Phone | Email |
|
|
3
|
+
+-------------+--------------+--------------------+-------------+------------------+
|
|
4
|
+
| New Company | First Last | Somewhere, US | 123-45-6789 | user@sample.com |
|
|
5
|
+
+-------------+--------------+--------------------+-------------+------------------+
|
|
6
|
+
| Old Company | First2 Last2 | Somewhere else, US | 987-65-4321 | user2@sample.com |
|
|
7
|
+
+-------------+--------------+--------------------+-------------+------------------+
|
|
8
|
+
| No Company | First3 Last3 | Elsewhere ZZ | 763-34-1234 | user3@sample.com |
|
|
9
|
+
+-------------+--------------+--------------------+-------------+------------------+
|
data/test/ref/a-csv.txt
ADDED
data/test/ref/a-html.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
┏━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━┓
|
|
2
|
+
┃ Company │ Name │ Address │ Phone │ Email ┃
|
|
3
|
+
┠─────────────┼──────────────┼────────────────────┼─────────────┼──────────────────┨
|
|
4
|
+
┃ New Company │ First Last │ Somewhere, US │ 123-45-6789 │ user@sample.com ┃
|
|
5
|
+
┠─────────────┼──────────────┼────────────────────┼─────────────┼──────────────────┨
|
|
6
|
+
┃ Old Company │ First2 Last2 │ Somewhere else, US │ 987-65-4321 │ user2@sample.com ┃
|
|
7
|
+
┠─────────────┼──────────────┼────────────────────┼─────────────┼──────────────────┨
|
|
8
|
+
┃ No Company │ First3 Last3 │ Elsewhere ZZ │ 763-34-1234 │ user3@sample.com ┃
|
|
9
|
+
┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━┛
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
┏━━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━┓
|
|
2
|
+
┃ Company │ Name │ Address │ Phone │ Email ┃
|
|
3
|
+
┠─────────────┼──────────────┼────────────────────┼─────────────┼──────────────────┨
|
|
4
|
+
┃ New Company │ First Last │ Somewhere, US │ 123-45-6789 │ user@sample.com ┃
|
|
5
|
+
┠─────────────┼──────────────┼────────────────────┼─────────────┼──────────────────┨
|
|
6
|
+
┃ Old Company │ First2 Last2 │ Somewhere else, US │ 987-65-4321 │ user2@sample.com ┃
|
|
7
|
+
┠─────────────┼──────────────┼────────────────────┼─────────────┼──────────────────┨
|
|
8
|
+
┃ No Company │ First3 Last3 │ Elsewhere ZZ │ 763-34-1234 │ user3@sample.com ┃
|
|
9
|
+
┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━┛
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
+-----------+-------+------------+
|
|
2
|
+
| Region | State | Sales |
|
|
3
|
+
+-----------+-------+------------+
|
|
4
|
+
| Northwest | WA | $2,100,500 |
|
|
5
|
+
+-----------+-------+------------+
|
|
6
|
+
| Northwest | OR | $900,800 |
|
|
7
|
+
+-----------+-------+------------+
|
|
8
|
+
| Northeast | NY | $8,120,000 |
|
|
9
|
+
+-----------+-------+------------+
|
|
10
|
+
| Northeast | MN | $489,500 |
|
|
11
|
+
+-----------+-------+------------+
|
|
12
|
+
| Southeast | GA | $2,111,200 |
|
|
13
|
+
+-----------+-------+------------+
|
|
14
|
+
| Southeast | FL | $9,388,000 |
|
|
15
|
+
+-----------+-------+------------+
|
|
16
|
+
| Southwest | AZ | $7,377,000 |
|
|
17
|
+
+-----------+-------+------------+
|
data/test/ref/b-csv.txt
ADDED
data/test/ref/b-html.txt
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<table>
|
|
2
|
+
<tr>
|
|
3
|
+
<th>Region</th>
|
|
4
|
+
<th>State</th>
|
|
5
|
+
<th>Sales</th>
|
|
6
|
+
</tr>
|
|
7
|
+
<tr>
|
|
8
|
+
<td>Northwest</td>
|
|
9
|
+
<td>WA</td>
|
|
10
|
+
<td>$2,100,500</td>
|
|
11
|
+
</tr>
|
|
12
|
+
<tr>
|
|
13
|
+
<td>Northwest</td>
|
|
14
|
+
<td>OR</td>
|
|
15
|
+
<td>$900,800</td>
|
|
16
|
+
</tr>
|
|
17
|
+
<tr>
|
|
18
|
+
<td>Northeast</td>
|
|
19
|
+
<td>NY</td>
|
|
20
|
+
<td>$8,120,000</td>
|
|
21
|
+
</tr>
|
|
22
|
+
<tr>
|
|
23
|
+
<td>Northeast</td>
|
|
24
|
+
<td>MN</td>
|
|
25
|
+
<td>$489,500</td>
|
|
26
|
+
</tr>
|
|
27
|
+
<tr>
|
|
28
|
+
<td>Southeast</td>
|
|
29
|
+
<td>GA</td>
|
|
30
|
+
<td>$2,111,200</td>
|
|
31
|
+
</tr>
|
|
32
|
+
<tr>
|
|
33
|
+
<td>Southeast</td>
|
|
34
|
+
<td>FL</td>
|
|
35
|
+
<td>$9,388,000</td>
|
|
36
|
+
</tr>
|
|
37
|
+
<tr>
|
|
38
|
+
<td>Southwest</td>
|
|
39
|
+
<td>AZ</td>
|
|
40
|
+
<td>$7,377,000</td>
|
|
41
|
+
</tr>
|
|
42
|
+
</table>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
┏━━━━━━━━━━━┯━━━━━━━┯━━━━━━━━━━━━┓
|
|
2
|
+
┃ Region │ State │ Sales ┃
|
|
3
|
+
┠───────────┼───────┼────────────┨
|
|
4
|
+
┃ Northwest │ WA │ $2,100,500 ┃
|
|
5
|
+
┠───────────┼───────┼────────────┨
|
|
6
|
+
┃ Northwest │ OR │ $900,800 ┃
|
|
7
|
+
┠───────────┼───────┼────────────┨
|
|
8
|
+
┃ Northeast │ NY │ $8,120,000 ┃
|
|
9
|
+
┠───────────┼───────┼────────────┨
|
|
10
|
+
┃ Northeast │ MN │ $489,500 ┃
|
|
11
|
+
┠───────────┼───────┼────────────┨
|
|
12
|
+
┃ Southeast │ GA │ $2,111,200 ┃
|
|
13
|
+
┠───────────┼───────┼────────────┨
|
|
14
|
+
┃ Southeast │ FL │ $9,388,000 ┃
|
|
15
|
+
┠───────────┼───────┼────────────┨
|
|
16
|
+
┃ Southwest │ AZ │ $7,377,000 ┃
|
|
17
|
+
┗━━━━━━━━━━━┷━━━━━━━┷━━━━━━━━━━━━┛
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
╔═══════════╦═══════╦════════════╗
|
|
2
|
+
║ Region ║ State ║ Sales ║
|
|
3
|
+
╠═══════════╬═══════╬════════════╣
|
|
4
|
+
║ Northwest ║ WA ║ $2,100,500 ║
|
|
5
|
+
╠═══════════╬═══════╬════════════╣
|
|
6
|
+
║ Northwest ║ OR ║ $900,800 ║
|
|
7
|
+
╠═══════════╬═══════╬════════════╣
|
|
8
|
+
║ Northeast ║ NY ║ $8,120,000 ║
|
|
9
|
+
╠═══════════╬═══════╬════════════╣
|
|
10
|
+
║ Northeast ║ MN ║ $489,500 ║
|
|
11
|
+
╠═══════════╬═══════╬════════════╣
|
|
12
|
+
║ Southeast ║ GA ║ $2,111,200 ║
|
|
13
|
+
╠═══════════╬═══════╬════════════╣
|
|
14
|
+
║ Southeast ║ FL ║ $9,388,000 ║
|
|
15
|
+
╠═══════════╬═══════╬════════════╣
|
|
16
|
+
║ Southwest ║ AZ ║ $7,377,000 ║
|
|
17
|
+
╚═══════════╩═══════╩════════════╝
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
╔═══════════╤═══════╤════════════╗
|
|
2
|
+
║ Region │ State │ Sales ║
|
|
3
|
+
╟───────────┼───────┼────────────╢
|
|
4
|
+
║ Northwest │ WA │ $2,100,500 ║
|
|
5
|
+
╟───────────┼───────┼────────────╢
|
|
6
|
+
║ Northwest │ OR │ $900,800 ║
|
|
7
|
+
╟───────────┼───────┼────────────╢
|
|
8
|
+
║ Northeast │ NY │ $8,120,000 ║
|
|
9
|
+
╟───────────┼───────┼────────────╢
|
|
10
|
+
║ Northeast │ MN │ $489,500 ║
|
|
11
|
+
╟───────────┼───────┼────────────╢
|
|
12
|
+
║ Southeast │ GA │ $2,111,200 ║
|
|
13
|
+
╟───────────┼───────┼────────────╢
|
|
14
|
+
║ Southeast │ FL │ $9,388,000 ║
|
|
15
|
+
╟───────────┼───────┼────────────╢
|
|
16
|
+
║ Southwest │ AZ │ $7,377,000 ║
|
|
17
|
+
╚═══════════╧═══════╧════════════╝
|
|
@@ -2,18 +2,74 @@
|
|
|
2
2
|
|
|
3
3
|
$LOAD_PATH.unshift '.', './test', './lib'
|
|
4
4
|
|
|
5
|
+
$refdir = 'test/ref' # where the test reference output lives
|
|
6
|
+
|
|
7
|
+
# if 'save' anywhere as an argument, the outputs are saved as reference
|
|
8
|
+
# test output.
|
|
9
|
+
|
|
10
|
+
$verbose = $save = nil
|
|
11
|
+
ARGV.each_with_index do |arg, x|
|
|
12
|
+
case arg
|
|
13
|
+
when 'save'
|
|
14
|
+
$save = true
|
|
15
|
+
ARGV.delete_at(x)
|
|
16
|
+
when '-v', '--verbose'
|
|
17
|
+
$verbose = true
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
5
21
|
require 'array/formatter'
|
|
6
22
|
require 'test-helper'
|
|
7
23
|
|
|
8
24
|
class Test_Array_Formatter < MiniTest::Unit::TestCase
|
|
9
25
|
|
|
26
|
+
def ref_filename name, kind
|
|
27
|
+
"#{$refdir}/#{name}-#{kind}.txt"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def read_ref name, kind
|
|
31
|
+
filename = ref_filename(name, kind)
|
|
32
|
+
ref = nil
|
|
33
|
+
if File.exist?(filename)
|
|
34
|
+
File.open(filename) { |file| ref = file.read }
|
|
35
|
+
end
|
|
36
|
+
ref
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def write_ref name, kind, out
|
|
40
|
+
filename = ref_filename(name, kind)
|
|
41
|
+
unless Dir.exist?($refdir)
|
|
42
|
+
Dir.mkdir $refdir
|
|
43
|
+
puts "Created #{$refdir}" if $verbose
|
|
44
|
+
end
|
|
45
|
+
File.open(filename, 'w+') { |file| file.write out }
|
|
46
|
+
printf "%d lines written to %s\n", (out.count("\n")+1), filename
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def check actual, name, kind
|
|
50
|
+
if $verbose
|
|
51
|
+
puts ""
|
|
52
|
+
puts actual
|
|
53
|
+
end
|
|
54
|
+
unless $save
|
|
55
|
+
expected = read_ref(name, kind)
|
|
56
|
+
if expected
|
|
57
|
+
assert_equal actual.strip, expected.strip, "Error: at #{caller.first}:"
|
|
58
|
+
else
|
|
59
|
+
puts "No reference output to compare with"
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
write_ref name, kind, actual
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
10
66
|
@@a = [ %w( Company Name Address Phone Email ),
|
|
11
67
|
[ 'New Company', 'First Last', 'Somewhere, US', '123-45-6789', 'user@sample.com' ],
|
|
12
68
|
[ 'Old Company', 'First2 Last2', 'Somewhere else, US', '987-65-4321', 'user2@sample.com' ],
|
|
13
69
|
[ 'No Company', 'First3 Last3', 'Elsewhere ZZ', '763-34-1234', 'user3@sample.com' ]
|
|
14
70
|
]
|
|
15
71
|
|
|
16
|
-
@@
|
|
72
|
+
@@b = [ %w( Region State Sales ),
|
|
17
73
|
%w( Northwest WA $2,100,500 ),
|
|
18
74
|
%w( Northwest OR $900,800 ),
|
|
19
75
|
%w( Northeast NY $8,120,000 ),
|
|
@@ -21,24 +77,56 @@ class Test_Array_Formatter < MiniTest::Unit::TestCase
|
|
|
21
77
|
%w( Southeast GA $2,111,200 ),
|
|
22
78
|
%w( Southeast FL $9,388,000 ),
|
|
23
79
|
%w( Southwest AZ $7,377,000 ) ]
|
|
24
|
-
|
|
25
80
|
|
|
26
|
-
def
|
|
81
|
+
def test_a_table_ascii
|
|
27
82
|
s = @@a.to_table
|
|
28
|
-
|
|
83
|
+
check s, :a, :ascii
|
|
29
84
|
end
|
|
30
85
|
|
|
31
|
-
def
|
|
86
|
+
def test_a_table_unicode
|
|
32
87
|
s = @@a.to_table(:unicode)
|
|
33
|
-
|
|
88
|
+
check s, :a, :unicode
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_a_table_unicode_single
|
|
92
|
+
s = @@a.to_table(:unicode_single)
|
|
93
|
+
check s, :a, :unicode_single
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def test_b_table_ascii
|
|
97
|
+
s = @@b.to_table
|
|
98
|
+
check s, :b, :ascii
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_b_table_unicode
|
|
102
|
+
s = @@b.to_table(:unicode)
|
|
103
|
+
check s, :b, :unicode
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def test_b_table_unicode_double
|
|
107
|
+
s = @@b.to_table(:unicode_double)
|
|
108
|
+
check s, :b, :unicode_double
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_b_table_unicode_mixed
|
|
112
|
+
s = @@b.to_table(:unicode_mixed)
|
|
113
|
+
check s, :b, :unicode_mixed
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def test_a_to_csv
|
|
117
|
+
check @@a.to_csv, :a, :csv
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_b_to_csv
|
|
121
|
+
check @@b.to_csv, :b, :csv
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def test_a_to_html
|
|
125
|
+
check @@a.to_csv, :a, :html
|
|
34
126
|
end
|
|
35
127
|
|
|
36
|
-
def
|
|
37
|
-
|
|
38
|
-
puts s
|
|
39
|
-
puts ''
|
|
40
|
-
s = @@a2.to_table(:unicode)
|
|
41
|
-
puts s
|
|
128
|
+
def test_b_to_html
|
|
129
|
+
check @@b.to_html, :b, :html
|
|
42
130
|
end
|
|
43
131
|
|
|
44
132
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: array-formatter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alan Stebbens
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-09-
|
|
11
|
+
date: 2013-09-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -55,6 +55,17 @@ files:
|
|
|
55
55
|
- array-formatter.gemspec
|
|
56
56
|
- lib/array/formatter.rb
|
|
57
57
|
- lib/array/formatter/version.rb
|
|
58
|
+
- test/ref/a-ascii.txt
|
|
59
|
+
- test/ref/a-csv.txt
|
|
60
|
+
- test/ref/a-html.txt
|
|
61
|
+
- test/ref/a-unicode.txt
|
|
62
|
+
- test/ref/a-unicode_single.txt
|
|
63
|
+
- test/ref/b-ascii.txt
|
|
64
|
+
- test/ref/b-csv.txt
|
|
65
|
+
- test/ref/b-html.txt
|
|
66
|
+
- test/ref/b-unicode.txt
|
|
67
|
+
- test/ref/b-unicode_double.txt
|
|
68
|
+
- test/ref/b-unicode_mixed.txt
|
|
58
69
|
- test/test-array-formatter.rb
|
|
59
70
|
- test/test-helper.rb
|
|
60
71
|
homepage: https://gitlab.com/as/array-formatter
|
|
@@ -82,5 +93,16 @@ signing_key:
|
|
|
82
93
|
specification_version: 4
|
|
83
94
|
summary: Format an array of arrays in one of serveral string formats
|
|
84
95
|
test_files:
|
|
96
|
+
- test/ref/a-ascii.txt
|
|
97
|
+
- test/ref/a-csv.txt
|
|
98
|
+
- test/ref/a-html.txt
|
|
99
|
+
- test/ref/a-unicode.txt
|
|
100
|
+
- test/ref/a-unicode_single.txt
|
|
101
|
+
- test/ref/b-ascii.txt
|
|
102
|
+
- test/ref/b-csv.txt
|
|
103
|
+
- test/ref/b-html.txt
|
|
104
|
+
- test/ref/b-unicode.txt
|
|
105
|
+
- test/ref/b-unicode_double.txt
|
|
106
|
+
- test/ref/b-unicode_mixed.txt
|
|
85
107
|
- test/test-array-formatter.rb
|
|
86
108
|
- test/test-helper.rb
|