tty 0.0.3 → 0.0.4
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.
- data/README.md +7 -3
- data/Rakefile +2 -0
- data/lib/tty/support/equatable.rb +151 -0
- data/lib/tty/table/operation/alignment.rb +40 -13
- data/lib/tty/table/operation/alignment_set.rb +17 -6
- data/lib/tty/table/operation/truncation.rb +42 -0
- data/lib/tty/table/renderer/basic.rb +53 -32
- data/lib/tty/table/renderer.rb +17 -0
- data/lib/tty/table/validatable.rb +0 -3
- data/lib/tty/table.rb +30 -36
- data/lib/tty/version.rb +1 -1
- data/lib/tty.rb +2 -0
- data/spec/tty/support/equatable_spec.rb +206 -0
- data/spec/tty/table/access_spec.rb +8 -1
- data/spec/tty/table/eql_spec.rb +7 -1
- data/spec/tty/table/initialize_spec.rb +45 -37
- data/spec/tty/table/operation/alignment/format_spec.rb +13 -5
- data/spec/tty/table/operation/alignment_set/align_rows_spec.rb +4 -4
- data/spec/tty/table/operation/truncation/truncate_spec.rb +22 -0
- data/spec/tty/table/options_spec.rb +8 -2
- data/spec/tty/table/renderer/basic/alignment_spec.rb +40 -0
- data/spec/tty/table/renderer/basic/extract_column_widths_spec.rb +23 -0
- data/spec/tty/table/renderer/basic/new_spec.rb +11 -0
- data/spec/tty/table/renderer/basic/render_spec.rb +48 -0
- data/spec/tty/table/renderer/basic_spec.rb +0 -64
- data/spec/tty/table/renderer_spec.rb +2 -2
- data/tasks/metrics/cane.rake +12 -0
- data/tasks/metrics/flog.rake +15 -0
- data/tasks/metrics/reek.rake +13 -0
- metadata +25 -8
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table::Renderer::Basic, '#extract_column_widths' do
|
6
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
7
|
+
|
8
|
+
subject { described_class.new }
|
9
|
+
|
10
|
+
it 'calculates column widths' do
|
11
|
+
rows = [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']]
|
12
|
+
table = TTY::Table.new rows, :renderer => :basic
|
13
|
+
subject.render(table)
|
14
|
+
table.column_widths.should == [5,6]
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'calcualtes column widths with header' do
|
18
|
+
header = ['header1', 'head2', 'h3']
|
19
|
+
table = TTY::Table.new header, rows
|
20
|
+
subject.render(table)
|
21
|
+
table.column_widths.should == [7,5,2]
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe TTY::Table::Renderer::Basic, '#render' do
|
6
|
+
let(:header) { ['h1', 'h2', 'h3'] }
|
7
|
+
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
8
|
+
|
9
|
+
it 'displays table without styling' do
|
10
|
+
table = TTY::Table.new :renderer => :basic
|
11
|
+
table << rows[0] << rows[1]
|
12
|
+
table.to_s.should == <<-EOS.normalize
|
13
|
+
a1 a2 a3
|
14
|
+
b1 b2 b3
|
15
|
+
EOS
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'displays table with header' do
|
19
|
+
table = TTY::Table.new :header => header, :renderer => :basic
|
20
|
+
table << rows[0] << rows[1]
|
21
|
+
table.to_s.should == <<-EOS.normalize
|
22
|
+
h1 h2 h3
|
23
|
+
a1 a2 a3
|
24
|
+
b1 b2 b3
|
25
|
+
EOS
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'displays table according to widths' do
|
29
|
+
header = ['h1', 'h2']
|
30
|
+
rows = [['aaa1', 'a2'], ['b1', 'bb1']]
|
31
|
+
table = TTY::Table.new header, rows, :renderer => :basic
|
32
|
+
table.to_s.should == <<-EOS.normalize
|
33
|
+
h1 h2
|
34
|
+
aaa1 a2
|
35
|
+
b1 bb1
|
36
|
+
EOS
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'header greater than row sizes' do
|
40
|
+
header = ['header1', 'header2', 'header3']
|
41
|
+
table = TTY::Table.new header, rows, :renderer => :basic
|
42
|
+
table.to_s.should == <<-EOS.normalize
|
43
|
+
header1 header2 header3
|
44
|
+
a1 a2 a3
|
45
|
+
b1 b2 b3
|
46
|
+
EOS
|
47
|
+
end
|
48
|
+
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe TTY::Table::Renderer::Basic do
|
6
|
-
let(:renderer) { TTY::Table::Renderer::Basic.new }
|
7
|
-
let(:header) { ['Header1', 'Header2'] }
|
8
|
-
let(:rows) { [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3']] }
|
9
|
-
|
10
|
-
subject { described_class.new }
|
11
|
-
|
12
|
-
it { should respond_to(:render) }
|
13
|
-
|
14
|
-
context '#extract_column_widths' do
|
15
|
-
it 'calculates column widths' do
|
16
|
-
rows = [['a1a', 'a2a2a2'], ['b1b1b', 'b2b2']]
|
17
|
-
subject.extract_column_widths(rows).should == [5,6]
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context '#render' do
|
22
|
-
it 'displays table without styling' do
|
23
|
-
table = TTY::Table.new :header => header, :renderer => :basic
|
24
|
-
table << rows[0]
|
25
|
-
table << rows[1]
|
26
|
-
table.to_s.should == <<-EOS.normalize
|
27
|
-
a1 a2 a3
|
28
|
-
b1 b2 b3
|
29
|
-
EOS
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'displays table according to widths' do
|
33
|
-
rows = [['aaa1', 'a2'], ['b1', 'bb1']]
|
34
|
-
table = TTY::Table.new header, rows, :renderer => :basic
|
35
|
-
table.to_s.should == <<-EOS.normalize
|
36
|
-
aaa1 a2
|
37
|
-
b1 bb1
|
38
|
-
EOS
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'alignment' do
|
43
|
-
it 'aligns left by default' do
|
44
|
-
rows = [['aaaaa', 'a'], ['b', 'bbbbb']]
|
45
|
-
table = TTY::Table.new header, rows, :renderer => :basic
|
46
|
-
table.to_s.should == <<-EOS.normalize
|
47
|
-
aaaaa a
|
48
|
-
b bbbbb
|
49
|
-
EOS
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'aligns table elements' do
|
53
|
-
rows = [['aaaaa', 'a'], ['b', 'bbbbb']]
|
54
|
-
table = TTY::Table.new header, rows, :renderer => :basic,
|
55
|
-
:column_aligns => [:left, :right]
|
56
|
-
table.to_s.should == <<-EOS.normalize
|
57
|
-
aaaaa a
|
58
|
-
b bbbbb
|
59
|
-
EOS
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
begin
|
2
|
+
require 'flog'
|
3
|
+
|
4
|
+
namespace :metrics do
|
5
|
+
desc 'Analyze for code complexity'
|
6
|
+
task :flog do
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
rescue LoadError
|
12
|
+
task :flog do
|
13
|
+
warn "Flog is not available. In order to run reek, you must: gem install flog"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require 'reek/rake/task'
|
3
|
+
|
4
|
+
namespace :metrics do
|
5
|
+
Reek::Rake::Task.new do |t|
|
6
|
+
t.fail_on_error = false
|
7
|
+
end
|
8
|
+
end
|
9
|
+
rescue LoadError
|
10
|
+
task :reek do
|
11
|
+
warn "Reek is not available. In order to run reek, you must: gem install reek"
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152566920 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152566920
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152566320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152566320
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: yard
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152565580 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152565580
|
47
47
|
description: Toolbox for developing CLI clients
|
48
48
|
email:
|
49
49
|
- ''
|
@@ -65,12 +65,14 @@ files:
|
|
65
65
|
- lib/tty/support/coercion.rb
|
66
66
|
- lib/tty/support/conversion.rb
|
67
67
|
- lib/tty/support/delegatable.rb
|
68
|
+
- lib/tty/support/equatable.rb
|
68
69
|
- lib/tty/support/utils.rb
|
69
70
|
- lib/tty/system.rb
|
70
71
|
- lib/tty/table.rb
|
71
72
|
- lib/tty/table/error.rb
|
72
73
|
- lib/tty/table/operation/alignment.rb
|
73
74
|
- lib/tty/table/operation/alignment_set.rb
|
75
|
+
- lib/tty/table/operation/truncation.rb
|
74
76
|
- lib/tty/table/renderer.rb
|
75
77
|
- lib/tty/table/renderer/basic.rb
|
76
78
|
- lib/tty/table/renderer/color.rb
|
@@ -83,6 +85,7 @@ files:
|
|
83
85
|
- spec/tty/support/coercion_spec.rb
|
84
86
|
- spec/tty/support/conversion_spec.rb
|
85
87
|
- spec/tty/support/delegatable_spec.rb
|
88
|
+
- spec/tty/support/equatable_spec.rb
|
86
89
|
- spec/tty/support/fixtures/classes.rb
|
87
90
|
- spec/tty/system/platform_spec.rb
|
88
91
|
- spec/tty/table/access_spec.rb
|
@@ -96,12 +99,20 @@ files:
|
|
96
99
|
- spec/tty/table/operation/alignment_set/each_spec.rb
|
97
100
|
- spec/tty/table/operation/alignment_set/new_spec.rb
|
98
101
|
- spec/tty/table/operation/alignment_set/to_ary_spec.rb
|
102
|
+
- spec/tty/table/operation/truncation/truncate_spec.rb
|
99
103
|
- spec/tty/table/options_spec.rb
|
100
104
|
- spec/tty/table/properties_spec.rb
|
105
|
+
- spec/tty/table/renderer/basic/alignment_spec.rb
|
106
|
+
- spec/tty/table/renderer/basic/extract_column_widths_spec.rb
|
107
|
+
- spec/tty/table/renderer/basic/new_spec.rb
|
108
|
+
- spec/tty/table/renderer/basic/render_spec.rb
|
101
109
|
- spec/tty/table/renderer/basic_spec.rb
|
102
110
|
- spec/tty/table/renderer_spec.rb
|
103
111
|
- spec/tty/table/validatable_spec.rb
|
104
112
|
- spec/tty/terminal/size_spec.rb
|
113
|
+
- tasks/metrics/cane.rake
|
114
|
+
- tasks/metrics/flog.rake
|
115
|
+
- tasks/metrics/reek.rake
|
105
116
|
- tty.gemspec
|
106
117
|
homepage: http://github.com/peter-murach/tty
|
107
118
|
licenses: []
|
@@ -133,6 +144,7 @@ test_files:
|
|
133
144
|
- spec/tty/support/coercion_spec.rb
|
134
145
|
- spec/tty/support/conversion_spec.rb
|
135
146
|
- spec/tty/support/delegatable_spec.rb
|
147
|
+
- spec/tty/support/equatable_spec.rb
|
136
148
|
- spec/tty/support/fixtures/classes.rb
|
137
149
|
- spec/tty/system/platform_spec.rb
|
138
150
|
- spec/tty/table/access_spec.rb
|
@@ -146,8 +158,13 @@ test_files:
|
|
146
158
|
- spec/tty/table/operation/alignment_set/each_spec.rb
|
147
159
|
- spec/tty/table/operation/alignment_set/new_spec.rb
|
148
160
|
- spec/tty/table/operation/alignment_set/to_ary_spec.rb
|
161
|
+
- spec/tty/table/operation/truncation/truncate_spec.rb
|
149
162
|
- spec/tty/table/options_spec.rb
|
150
163
|
- spec/tty/table/properties_spec.rb
|
164
|
+
- spec/tty/table/renderer/basic/alignment_spec.rb
|
165
|
+
- spec/tty/table/renderer/basic/extract_column_widths_spec.rb
|
166
|
+
- spec/tty/table/renderer/basic/new_spec.rb
|
167
|
+
- spec/tty/table/renderer/basic/render_spec.rb
|
151
168
|
- spec/tty/table/renderer/basic_spec.rb
|
152
169
|
- spec/tty/table/renderer_spec.rb
|
153
170
|
- spec/tty/table/validatable_spec.rb
|