tablesmith 0.4.0 → 0.6.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 +5 -5
- data/lib/tablesmith.rb +3 -0
- data/lib/tablesmith/active_record_source.rb +4 -2
- data/lib/tablesmith/array_rows_source.rb +3 -1
- data/lib/tablesmith/delegated_array_class.rb +39 -0
- data/lib/tablesmith/hash_rows_base.rb +4 -1
- data/lib/tablesmith/hash_rows_source.rb +8 -8
- data/lib/tablesmith/html_formatter.rb +3 -5
- data/lib/tablesmith/table.rb +53 -40
- data/lib/tablesmith/version.rb +3 -1
- data/spec/active_record_table_spec.rb +53 -49
- data/spec/array_table_spec.rb +69 -2
- data/spec/fixtures.rb +2 -0
- data/spec/hash_rows_table_spec.rb +15 -12
- data/spec/hash_table_spec.rb +23 -1
- data/spec/spec_helper.rb +6 -2
- data/spec/table_spec.rb +21 -9
- metadata +98 -24
- data/.gitignore +0 -4
- data/.rspec +0 -2
- data/.rubocop.yml +0 -11
- data/.ruby-version +0 -1
- data/.travis.yml +0 -1
- data/Gemfile +0 -4
- data/LICENSE +0 -19
- data/README.md +0 -35
- data/Rakefile +0 -11
- data/tablesmith.gemspec +0 -28
data/spec/array_table_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'Array Source' do
|
@@ -9,6 +11,71 @@ describe 'Array Source' do
|
|
9
11
|
| d | e | f |
|
10
12
|
+---+---+---+
|
11
13
|
TABLE
|
12
|
-
[%w
|
14
|
+
[%w[a b c], %w[d e f]].to_table.to_s.should == expected
|
15
|
+
end
|
16
|
+
|
17
|
+
def do_just_works_test(meth_id)
|
18
|
+
orig_stdout = $stdout
|
19
|
+
sio = StringIO.new
|
20
|
+
$stdout = sio
|
21
|
+
send(meth_id, [%w[a b c], %w[d e f]].to_table)
|
22
|
+
sio.string
|
23
|
+
ensure
|
24
|
+
$stdout = orig_stdout
|
25
|
+
end
|
26
|
+
|
27
|
+
def just_works(meth_id)
|
28
|
+
expected = <<~TABLE
|
29
|
+
+---+---+---+
|
30
|
+
| a | b | c |
|
31
|
+
+---+---+---+
|
32
|
+
| d | e | f |
|
33
|
+
+---+---+---+
|
34
|
+
TABLE
|
35
|
+
|
36
|
+
actual = do_just_works_test(meth_id)
|
37
|
+
actual.should == expected
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'just works with print' do
|
41
|
+
just_works(:print)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'just works with puts' do
|
45
|
+
just_works(:puts)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'just works with p' do
|
49
|
+
expected = <<~TABLE
|
50
|
+
+---+---+---+
|
51
|
+
| a | b | c |
|
52
|
+
+---+---+---+
|
53
|
+
| d | e | f |
|
54
|
+
+---+---+---+
|
55
|
+
TABLE
|
56
|
+
|
57
|
+
actual = do_just_works_test(:p)
|
58
|
+
actual.should == "#{expected}\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'just works with inspect' do
|
62
|
+
expected = <<~TABLE
|
63
|
+
+---+---+---+
|
64
|
+
| a | b | c |
|
65
|
+
+---+---+---+
|
66
|
+
| d | e | f |
|
67
|
+
+---+---+---+
|
68
|
+
TABLE
|
69
|
+
[%w[a b c], %w[d e f]].to_table.inspect.should == expected
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'just works with inspect two element integer array' do
|
73
|
+
expected = <<~TABLE
|
74
|
+
+---+
|
75
|
+
| 1 |
|
76
|
+
| 3 |
|
77
|
+
+---+
|
78
|
+
TABLE
|
79
|
+
[1, 3].to_table.inspect.should == expected
|
13
80
|
end
|
14
|
-
end
|
81
|
+
end
|
data/spec/fixtures.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'HashRowsSource' do
|
@@ -9,7 +11,7 @@ describe 'HashRowsSource' do
|
|
9
11
|
| 1 | 2 |
|
10
12
|
+---+---+
|
11
13
|
TABLE
|
12
|
-
[{a: 1, b: 2}].to_table.
|
14
|
+
[{ a: 1, b: 2 }].to_table.to_s.should == expected
|
13
15
|
end
|
14
16
|
|
15
17
|
it 'outputs text table of hash row with nested Array' do
|
@@ -20,7 +22,7 @@ describe 'HashRowsSource' do
|
|
20
22
|
| 1 | [1, 2] |
|
21
23
|
+---+--------+
|
22
24
|
TABLE
|
23
|
-
[{a: 1, b: [1, 2]}].to_table.
|
25
|
+
[{ a: 1, b: [1, 2] }].to_table.to_s.should == expected
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'outputs text table of hash row with nested Hash' do
|
@@ -31,7 +33,7 @@ describe 'HashRowsSource' do
|
|
31
33
|
| 1 | {:c=>3} |
|
32
34
|
+---+---------+
|
33
35
|
TABLE
|
34
|
-
[{a: 1, b: {c: 3}}].to_table.
|
36
|
+
[{ a: 1, b: { c: 3 } }].to_table.to_s.should == expected
|
35
37
|
end
|
36
38
|
|
37
39
|
it 'outputs text table of mixed columns hash rows with default columns' do
|
@@ -44,12 +46,14 @@ describe 'HashRowsSource' do
|
|
44
46
|
+---+---+---+
|
45
47
|
TABLE
|
46
48
|
[
|
47
|
-
{a: 1, b: 2},
|
48
|
-
{a: 2, c: '!'}
|
49
|
-
].to_table.
|
49
|
+
{ a: 1, b: 2 },
|
50
|
+
{ a: 2, c: '!' }
|
51
|
+
].to_table.to_s.should == expected
|
50
52
|
end
|
51
53
|
|
52
54
|
it 'outputs text table of deep hash rows with defined columns' do
|
55
|
+
pending
|
56
|
+
|
53
57
|
expected = <<~TABLE
|
54
58
|
+---+---+---+
|
55
59
|
| a | b |
|
@@ -59,19 +63,18 @@ describe 'HashRowsSource' do
|
|
59
63
|
| 1 | 2 | 2 |
|
60
64
|
+---+---+---+
|
61
65
|
TABLE
|
62
|
-
b = [{a: 1, b: {c: 2, d: 2}}].to_table
|
66
|
+
b = [{ a: 1, b: { c: 2, d: 2 } }].to_table
|
63
67
|
def b.columns
|
64
68
|
[
|
65
69
|
Column.new(name: :a),
|
66
|
-
{b: [
|
70
|
+
{ b: [
|
67
71
|
Column.new(name: :c)
|
68
|
-
]}
|
72
|
+
] }
|
69
73
|
]
|
70
74
|
end
|
71
75
|
|
72
76
|
# this would be nice.
|
73
|
-
|
74
|
-
pending
|
77
|
+
b.to_s.should == expected
|
75
78
|
end
|
76
79
|
|
77
80
|
it 'keeps OrderedHash keys in order' do
|
@@ -85,7 +88,7 @@ describe 'HashRowsSource' do
|
|
85
88
|
| 2 | 1 |
|
86
89
|
+---+---+
|
87
90
|
TABLE
|
88
|
-
h.to_table.
|
91
|
+
h.to_table.to_s.should == expected
|
89
92
|
end
|
90
93
|
|
91
94
|
it 'outputs text table of deep hash rows with default columns'
|
data/spec/hash_table_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe 'Hash Source' do
|
@@ -11,4 +13,24 @@ describe 'Hash Source' do
|
|
11
13
|
TABLE
|
12
14
|
{a: 1, b: 2, c: 3}.to_table.text_table.to_s.should == expected
|
13
15
|
end
|
14
|
-
|
16
|
+
|
17
|
+
it 'just works with print' do
|
18
|
+
expected = <<~TABLE
|
19
|
+
+---+---+---+
|
20
|
+
| a | b | c |
|
21
|
+
+---+---+---+
|
22
|
+
| 1 | 2 | 3 |
|
23
|
+
+---+---+---+
|
24
|
+
TABLE
|
25
|
+
|
26
|
+
begin
|
27
|
+
orig_stdout = $stdout
|
28
|
+
sio = StringIO.new
|
29
|
+
$stdout = sio
|
30
|
+
print({a: 1, b: 2, c: 3}.to_table)
|
31
|
+
sio.string.should == expected
|
32
|
+
ensure
|
33
|
+
$stdout = orig_stdout
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path('../
|
3
|
+
require File.expand_path('../lib/tablesmith', __dir__)
|
4
|
+
|
5
|
+
require File.expand_path('fixtures', __dir__)
|
6
|
+
|
7
|
+
RSpec.configuration.expect_with(:rspec) { |c| c.syntax = :should }
|
data/spec/table_spec.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
include Tablesmith
|
5
|
+
include Tablesmith # rubocop:disable Style/MixinUsage:
|
4
6
|
|
5
7
|
describe Table do
|
6
|
-
it 'should
|
8
|
+
it 'should delegate to the internal array' do
|
7
9
|
b = Table.new
|
8
10
|
b.length.should == 0
|
9
11
|
b << 1
|
@@ -13,12 +15,17 @@ describe Table do
|
|
13
15
|
b.class.should == Table
|
14
16
|
end
|
15
17
|
|
16
|
-
it 'should pass unmatched Array messages to all items' do
|
18
|
+
it 'should no longer pass unmatched Array messages to all items' do
|
19
|
+
# earlier pre-1.0 versions implemented method_missing in order to provide
|
20
|
+
# syntactic sugar for calling map on the underlying Array. But as time went
|
21
|
+
# on, it felt too heavy-handed and not worth it.
|
22
|
+
|
17
23
|
b = Table.new
|
18
24
|
b.length.should == 0
|
19
25
|
b << 1
|
20
26
|
b << '2'
|
21
|
-
b.to_i.should == [1, 2]
|
27
|
+
b.map(&:to_i).should == [1, 2]
|
28
|
+
-> { b.to_i }.should raise_error(NoMethodError)
|
22
29
|
end
|
23
30
|
|
24
31
|
it 'should handle empty Array' do
|
@@ -27,11 +34,11 @@ describe Table do
|
|
27
34
|
| (empty) |
|
28
35
|
+---------+
|
29
36
|
TEXT
|
30
|
-
[].to_table.
|
37
|
+
[].to_table.to_s.should == expected
|
31
38
|
end
|
32
39
|
|
33
40
|
it 'should handle a simple two row Array' do
|
34
|
-
a = [%w
|
41
|
+
a = [%w[a b c], %w[d e f]]
|
35
42
|
actual = a
|
36
43
|
expected = <<~TABLE
|
37
44
|
+---+---+---+
|
@@ -40,11 +47,11 @@ describe Table do
|
|
40
47
|
| d | e | f |
|
41
48
|
+---+---+---+
|
42
49
|
TABLE
|
43
|
-
actual.to_table.
|
50
|
+
actual.to_table.to_s.should == expected
|
44
51
|
end
|
45
52
|
|
46
53
|
it 'should output csv' do
|
47
|
-
a = [['a', 'b,s', 'c'], %w
|
54
|
+
a = [['a', 'b,s', 'c'], %w[d e f]]
|
48
55
|
actual = a
|
49
56
|
expected = <<~TABLE
|
50
57
|
a,"b,s",c
|
@@ -54,7 +61,7 @@ describe Table do
|
|
54
61
|
end
|
55
62
|
|
56
63
|
it 'should output html' do
|
57
|
-
actual = [%w[a b c], %w[d e f]]
|
64
|
+
actual = [%w[a b c], %w[d e f], %w[g h i]]
|
58
65
|
expected = <<~TABLE
|
59
66
|
<table>
|
60
67
|
<thead>
|
@@ -70,6 +77,11 @@ describe Table do
|
|
70
77
|
<td>e</td>
|
71
78
|
<td>f</td>
|
72
79
|
</tr>
|
80
|
+
<tr>
|
81
|
+
<td>g</td>
|
82
|
+
<td>h</td>
|
83
|
+
<td>i</td>
|
84
|
+
</tr>
|
73
85
|
</tbody>
|
74
86
|
</table>
|
75
87
|
TABLE
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tablesmith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chrismo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: text-table
|
@@ -30,16 +30,16 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.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
|
-
version: '
|
40
|
+
version: '4.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: appraisal
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,35 +53,63 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 12.3.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 12.3.3
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: rspec
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
72
100
|
requirements:
|
73
101
|
- - "~>"
|
74
102
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
103
|
+
version: '3.0'
|
76
104
|
type: :development
|
77
105
|
prerelease: false
|
78
106
|
version_requirements: !ruby/object:Gem::Requirement
|
79
107
|
requirements:
|
80
108
|
- - "~>"
|
81
109
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
110
|
+
version: '3.0'
|
83
111
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
112
|
+
name: rubocop
|
85
113
|
requirement: !ruby/object:Gem::Requirement
|
86
114
|
requirements:
|
87
115
|
- - ">="
|
@@ -95,7 +123,35 @@ dependencies:
|
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
97
125
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
126
|
+
name: rubocop_lineup
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop-performance
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop-rails
|
99
155
|
requirement: !ruby/object:Gem::Requirement
|
100
156
|
requirements:
|
101
157
|
- - ">="
|
@@ -108,6 +164,34 @@ dependencies:
|
|
108
164
|
- - ">="
|
109
165
|
- !ruby/object:Gem::Version
|
110
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: simplecov
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: sqlite3
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 1.3.6
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 1.3.6
|
111
195
|
description: Minimal console table
|
112
196
|
email:
|
113
197
|
- chrismo@clabs.org
|
@@ -115,18 +199,10 @@ executables: []
|
|
115
199
|
extensions: []
|
116
200
|
extra_rdoc_files: []
|
117
201
|
files:
|
118
|
-
- ".gitignore"
|
119
|
-
- ".rspec"
|
120
|
-
- ".rubocop.yml"
|
121
|
-
- ".ruby-version"
|
122
|
-
- ".travis.yml"
|
123
|
-
- Gemfile
|
124
|
-
- LICENSE
|
125
|
-
- README.md
|
126
|
-
- Rakefile
|
127
202
|
- lib/tablesmith.rb
|
128
203
|
- lib/tablesmith/active_record_source.rb
|
129
204
|
- lib/tablesmith/array_rows_source.rb
|
205
|
+
- lib/tablesmith/delegated_array_class.rb
|
130
206
|
- lib/tablesmith/hash_rows_base.rb
|
131
207
|
- lib/tablesmith/hash_rows_source.rb
|
132
208
|
- lib/tablesmith/html_formatter.rb
|
@@ -139,7 +215,6 @@ files:
|
|
139
215
|
- spec/hash_table_spec.rb
|
140
216
|
- spec/spec_helper.rb
|
141
217
|
- spec/table_spec.rb
|
142
|
-
- tablesmith.gemspec
|
143
218
|
homepage: http://github.com/livingsocial/tablesmith
|
144
219
|
licenses: []
|
145
220
|
metadata: {}
|
@@ -158,8 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
233
|
- !ruby/object:Gem::Version
|
159
234
|
version: '0'
|
160
235
|
requirements: []
|
161
|
-
|
162
|
-
rubygems_version: 2.6.13
|
236
|
+
rubygems_version: 3.0.3
|
163
237
|
signing_key:
|
164
238
|
specification_version: 4
|
165
239
|
summary: Minimal console table
|