terminal-table 1.4.3 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +5 -0
- data/README.rdoc +212 -130
- data/Todo.rdoc +0 -1
- data/examples/examples.rb +20 -7
- data/lib/terminal-table.rb +3 -7
- data/lib/terminal-table/cell.rb +49 -14
- data/lib/terminal-table/core_ext.rb +1 -21
- data/lib/terminal-table/row.rb +48 -0
- data/lib/terminal-table/separator.rb +14 -0
- data/lib/terminal-table/style.rb +61 -0
- data/lib/terminal-table/table.rb +138 -188
- data/lib/terminal-table/version.rb +1 -1
- data/spec/cell_spec.rb +38 -2
- data/spec/spec_helper.rb +1 -1
- data/spec/table_spec.rb +139 -65
- data/terminal-table.gemspec +4 -4
- metadata +8 -4
- data/lib/terminal-table/heading.rb +0 -10
data/spec/cell_spec.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'term/ansicolor'
|
3
|
+
|
4
|
+
class String; include Term::ANSIColor; end
|
1
5
|
|
2
6
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
7
|
|
@@ -5,14 +9,46 @@ describe Terminal::Table do
|
|
5
9
|
Cell = Terminal::Table::Cell
|
6
10
|
|
7
11
|
it "should default alignment to the left" do
|
8
|
-
cell = Cell.new
|
12
|
+
cell = Cell.new :value => 'foo', :table => Terminal::Table.new, :index => 0
|
9
13
|
cell.value.should == 'foo'
|
10
14
|
cell.alignment.should == :left
|
11
15
|
end
|
12
16
|
|
13
17
|
it "should allow overriding of alignment" do
|
14
|
-
cell = Cell.new
|
18
|
+
cell = Cell.new :value => 'foo', :alignment => :center, :table => Terminal::Table.new, :index => 0
|
15
19
|
cell.value.should == 'foo'
|
16
20
|
cell.alignment.should == :center
|
17
21
|
end
|
22
|
+
|
23
|
+
it "should allow :left, :right and :center for alignment" do
|
24
|
+
@cell = Cell.new :value => 'foo', :table => Terminal::Table.new, :index => 0
|
25
|
+
@cell.alignment = :left
|
26
|
+
@cell.alignment = :right
|
27
|
+
@cell.alignment = :center
|
28
|
+
lambda { @cell.alignment = "foo" }.should raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should allow multiline content" do
|
32
|
+
cell = Cell.new :value => "foo\nbarrissimo", :table => Terminal::Table.new, :index => 0
|
33
|
+
cell.value.should == "foo\nbarrissimo"
|
34
|
+
cell.lines.should == ['foo', 'barrissimo']
|
35
|
+
cell.value_for_column_width_recalc.should == 'barrissimo'
|
36
|
+
cell.render(1).should == " barrissimo "
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should allow colorized content" do
|
40
|
+
cell = Cell.new :value => "foo".red, :table => Terminal::Table.new, :index => 0
|
41
|
+
cell.value.should == "\e[31mfoo\e[0m"
|
42
|
+
cell.value_for_column_width_recalc.should == 'foo'
|
43
|
+
cell.render.should == " \e[31mfoo\e[0m "
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should render padding properly" do
|
47
|
+
@table = Terminal::Table.new(:rows => [['foo', '2'], ['3', '4']], :style => {:padding_right => 3})
|
48
|
+
cell = @table.rows.first.cells.first
|
49
|
+
cell.value.should == 'foo'
|
50
|
+
cell.alignment.should == :left
|
51
|
+
cell.render.should == " foo "
|
52
|
+
end
|
53
|
+
|
18
54
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/table_spec.rb
CHANGED
@@ -19,16 +19,16 @@ module Terminal
|
|
19
19
|
@table.column_with_headings(2).should == [3,6]
|
20
20
|
end
|
21
21
|
|
22
|
-
it "should select the columns with colspans > 1 in the index" do
|
23
|
-
|
24
|
-
|
25
|
-
end
|
22
|
+
#it "should select the columns with colspans > 1 in the index" do
|
23
|
+
# @table << [1,{:value => 2, :colspan => 2}]
|
24
|
+
# @table << [{:value => 3, :colspan => 2}, 4]
|
25
|
+
#end
|
26
26
|
|
27
27
|
it "should account for the colspan when selecting columns" do
|
28
28
|
@table << [1,2,3]
|
29
29
|
@table << [{:value => "4,5", :colspan => 2}, 6]
|
30
|
-
@table.column_with_headings(0).should == [1,
|
31
|
-
@table.column_with_headings(1).should == [2,
|
30
|
+
@table.column_with_headings(0).should == [1,"4,5"]
|
31
|
+
@table.column_with_headings(1).should == [2,"4,5"]
|
32
32
|
@table.column_with_headings(2).should == [3,6]
|
33
33
|
end
|
34
34
|
|
@@ -45,11 +45,6 @@ module Terminal
|
|
45
45
|
EOF
|
46
46
|
end
|
47
47
|
|
48
|
-
it "should convert rows to indexes" do
|
49
|
-
@table << [{:value => '7', :colspan => 2}, 88]
|
50
|
-
@table.row_to_index(@table.rows[0], 1).should == 2
|
51
|
-
end
|
52
|
-
|
53
48
|
it "should count columns" do
|
54
49
|
@table << [1, 2, 3]
|
55
50
|
@table.number_of_columns.should == 3
|
@@ -71,64 +66,27 @@ module Terminal
|
|
71
66
|
it "should select columns when using hashes" do
|
72
67
|
@table.headings = ['one', 'two']
|
73
68
|
@table.rows = [[{ :value => 'a', :align => :left }, 1], ['b', 2], ['c', 3]]
|
74
|
-
@table.column(0).should == [
|
75
|
-
end
|
76
|
-
|
77
|
-
it "should determine length of largest cell in a column" do
|
78
|
-
@table << ['foo', 'bar']
|
79
|
-
@table << ['big foo', 'big foo bar']
|
80
|
-
@table.length_of_largest_cell_in_column(1).should == 11
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should determine length of largest cell in a column with multi-column rows" do
|
84
|
-
@table << [1,2]
|
85
|
-
@table << [{:value => '123456789', :colspan => 2}]
|
86
|
-
# +-----+-----+
|
87
|
-
# | 1 | 2 |
|
88
|
-
# | 123456789 |
|
89
|
-
#
|
90
|
-
@table.length_of_largest_cell_in_column(0).should == 3
|
91
|
-
@table.length_of_largest_cell_in_column(1).should == 3
|
92
|
-
|
93
|
-
@table.render.should == <<-EOF.deindent
|
94
|
-
+-----+-----+
|
95
|
-
| 1 | 2 |
|
96
|
-
| 123456789 |
|
97
|
-
+-----+-----+
|
98
|
-
EOF
|
99
|
-
end
|
100
|
-
|
101
|
-
it "should determine length of largest cell in a column with multi-column rows, rounding up" do
|
102
|
-
@table << [1,2]
|
103
|
-
@table << [{:value => '1234567890', :colspan => 2}]
|
104
|
-
@table.length_of_largest_cell_in_column(0).should == 4
|
105
|
-
@table.length_of_largest_cell_in_column(1).should == 4
|
106
|
-
|
107
|
-
@table.render.should == <<-EOF.deindent
|
108
|
-
+------+------+
|
109
|
-
| 1 | 2 |
|
110
|
-
| 1234567890 |
|
111
|
-
+------+------+
|
112
|
-
EOF
|
69
|
+
@table.column(0).should == ['a', 'b', 'c']
|
113
70
|
end
|
114
71
|
|
115
72
|
it "should find column length" do
|
116
73
|
@table << ['foo', 'bar', 'a']
|
117
74
|
@table << ['big foo', 'big foo bar']
|
118
|
-
@table.
|
75
|
+
@table.column_width(1).should == 11
|
119
76
|
end
|
120
77
|
|
121
78
|
it "should find column length with headings" do
|
122
79
|
@table.headings = ['one', 'super long heading']
|
123
80
|
@table << ['foo', 'bar', 'a']
|
124
81
|
@table << ['big foo', 'big foo bar']
|
125
|
-
@table.
|
82
|
+
@table.column_width(1).should == 18
|
126
83
|
end
|
127
84
|
|
128
85
|
it "should render separators" do
|
129
86
|
@table.headings = ['Char', 'Num']
|
130
87
|
@table << ['a', 1]
|
131
|
-
|
88
|
+
separator = Terminal::Table::Separator.new(@table)
|
89
|
+
separator.render.should == '+------+-----+'
|
132
90
|
end
|
133
91
|
|
134
92
|
it "should add separator" do
|
@@ -136,11 +94,13 @@ module Terminal
|
|
136
94
|
@table.add_separator
|
137
95
|
@table << ['b', 2]
|
138
96
|
@table.rows.size.should == 2
|
139
|
-
@table.all_rows.size.should == 3
|
140
97
|
end
|
141
98
|
|
142
|
-
it "should
|
143
|
-
|
99
|
+
it "should render an empty table properly" do
|
100
|
+
@table.render.should == <<-EOF.deindent
|
101
|
+
++
|
102
|
+
++
|
103
|
+
EOF
|
144
104
|
end
|
145
105
|
|
146
106
|
it "should render properly" do
|
@@ -159,6 +119,60 @@ module Terminal
|
|
159
119
|
EOF
|
160
120
|
end
|
161
121
|
|
122
|
+
it "should render styles properly" do
|
123
|
+
@table.headings = ['Char', 'Num']
|
124
|
+
@table.style = {:border_x => "=", :border_y => ":", :border_i => "x", :padding_left => 0, :padding_right => 2}
|
125
|
+
@table << ['a', 1]
|
126
|
+
@table << ['b', 2]
|
127
|
+
@table << ['c', 3]
|
128
|
+
@table.style.padding_right.should == 2
|
129
|
+
@table.render.should == <<-EOF.deindent
|
130
|
+
x======x=====x
|
131
|
+
:Char :Num :
|
132
|
+
x======x=====x
|
133
|
+
:a :1 :
|
134
|
+
:b :2 :
|
135
|
+
:c :3 :
|
136
|
+
x======x=====x
|
137
|
+
EOF
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should render width properly" do
|
141
|
+
@table.headings = ['Char', 'Num']
|
142
|
+
@table << ['a', 1]
|
143
|
+
@table << ['b', 2]
|
144
|
+
@table << ['c', 3]
|
145
|
+
@table.style.width = 21
|
146
|
+
@table.render.should == <<-EOF.deindent
|
147
|
+
+---------+---------+
|
148
|
+
| Char | Num |
|
149
|
+
+---------+---------+
|
150
|
+
| a | 1 |
|
151
|
+
| b | 2 |
|
152
|
+
| c | 3 |
|
153
|
+
+---------+---------+
|
154
|
+
EOF
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should render title properly" do
|
158
|
+
@table.title = "Title"
|
159
|
+
@table.headings = ['Char', 'Num']
|
160
|
+
@table << ['a', 1]
|
161
|
+
@table << ['b', 2]
|
162
|
+
@table << ['c', 3]
|
163
|
+
@table.render.should == <<-EOF.deindent
|
164
|
+
+-------+-----+
|
165
|
+
| Title |
|
166
|
+
+-------+-----+
|
167
|
+
| Char | Num |
|
168
|
+
+-------+-----+
|
169
|
+
| a | 1 |
|
170
|
+
| b | 2 |
|
171
|
+
| c | 3 |
|
172
|
+
+-------+-----+
|
173
|
+
EOF
|
174
|
+
end
|
175
|
+
|
162
176
|
it "should render properly without headings" do
|
163
177
|
@table << ['a', 1]
|
164
178
|
@table << ['b', 2]
|
@@ -307,13 +321,13 @@ module Terminal
|
|
307
321
|
t.should == t
|
308
322
|
end
|
309
323
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
324
|
+
# it "should be equal with two empty tables" do
|
325
|
+
# table_one = Table.new
|
326
|
+
# table_two = Table.new
|
327
|
+
#
|
328
|
+
# table_one.should == table_two
|
329
|
+
# table_two.should == table_one
|
330
|
+
# end
|
317
331
|
|
318
332
|
it "should not be equal with different headings" do
|
319
333
|
table_one = Table.new
|
@@ -329,8 +343,6 @@ module Terminal
|
|
329
343
|
table_one = Table.new
|
330
344
|
table_two = Table.new
|
331
345
|
|
332
|
-
table_one.add_row "a"
|
333
|
-
|
334
346
|
table_one.should_not == table_two
|
335
347
|
table_two.should_not == table_one
|
336
348
|
end
|
@@ -447,5 +459,67 @@ module Terminal
|
|
447
459
|
+------+---+---+---+
|
448
460
|
EOF
|
449
461
|
end
|
462
|
+
|
463
|
+
it "should handle multiple colspan" do
|
464
|
+
@table.headings = [
|
465
|
+
'name',
|
466
|
+
{ :value => 'Values', :alignment => :right, :colspan => 2},
|
467
|
+
{ :value => 'Other values', :alignment => :right, :colspan => 2},
|
468
|
+
{ :value => 'Column 3', :alignment => :right, :colspan => 2}
|
469
|
+
]
|
470
|
+
|
471
|
+
3.times do |row_index|
|
472
|
+
row = ["row ##{row_index+1}"]
|
473
|
+
6.times do |i|
|
474
|
+
row << row_index*6 + i
|
475
|
+
end
|
476
|
+
@table.add_row(row)
|
477
|
+
end
|
478
|
+
|
479
|
+
@table.render.should == <<-EOF.deindent
|
480
|
+
+--------+----+----+-------+-------+-----+-----+
|
481
|
+
| name | Values | Other values | Column 3 |
|
482
|
+
+--------+----+----+-------+-------+-----+-----+
|
483
|
+
| row #1 | 0 | 1 | 2 | 3 | 4 | 5 |
|
484
|
+
| row #2 | 6 | 7 | 8 | 9 | 10 | 11 |
|
485
|
+
| row #3 | 12 | 13 | 14 | 15 | 16 | 17 |
|
486
|
+
+--------+----+----+-------+-------+-----+-----+
|
487
|
+
EOF
|
488
|
+
end
|
489
|
+
|
490
|
+
it "should render a table with only X cell borders" do
|
491
|
+
@table.style = {:border_x => "-", :border_y => "", :border_i => ""}
|
492
|
+
|
493
|
+
@table.headings = ['name', { :value => 'values', :alignment => :right, :colspan => 3}]
|
494
|
+
@table.headings = ['name', { :value => 'values', :colspan => 3}]
|
495
|
+
@table.rows = [['a', 1, 2, 3], ['b', 4, 5, 6], ['c', 7, 8, 9]]
|
496
|
+
|
497
|
+
@table.render.should == <<-EOF.strip
|
498
|
+
---------------
|
499
|
+
name values
|
500
|
+
---------------
|
501
|
+
a 1 2 3
|
502
|
+
b 4 5 6
|
503
|
+
c 7 8 9
|
504
|
+
---------------
|
505
|
+
EOF
|
506
|
+
end
|
507
|
+
|
508
|
+
it "should render a table without cell borders" do
|
509
|
+
@table.style = {:border_x => "", :border_y => "", :border_i => ""}
|
510
|
+
|
511
|
+
@table.headings = ['name', { :value => 'values', :alignment => :right, :colspan => 3}]
|
512
|
+
@table.headings = ['name', { :value => 'values', :colspan => 3}]
|
513
|
+
@table.rows = [['a', 1, 2, 3], ['b', 4, 5, 6], ['c', 7, 8, 9]]
|
514
|
+
|
515
|
+
@table.render.should == <<-EOF
|
516
|
+
|
517
|
+
name values
|
518
|
+
|
519
|
+
a 1 2 3
|
520
|
+
b 4 5 6
|
521
|
+
c 7 8 9
|
522
|
+
EOF
|
523
|
+
end
|
450
524
|
end
|
451
525
|
end
|
data/terminal-table.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{terminal-table}
|
5
|
-
s.version = "1.4.
|
5
|
+
s.version = "1.4.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk", "Scott J. Goldman"]
|
9
|
-
s.date = %q{2011-
|
9
|
+
s.date = %q{2011-11-07}
|
10
10
|
s.description = %q{Simple, feature rich ascii table generation library}
|
11
11
|
s.email = %q{tj@vision-media.ca}
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/
|
13
|
-
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "Todo.rdoc", "examples/examples.rb", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/table_helper.rb", "lib/terminal-table/version.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/row.rb", "lib/terminal-table/separator.rb", "lib/terminal-table/style.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
13
|
+
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "Todo.rdoc", "examples/examples.rb", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/table_helper.rb", "lib/terminal-table/version.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/row.rb", "lib/terminal-table/separator.rb", "lib/terminal-table/style.rb", "spec/cell_spec.rb", "spec/core_ext_spec.rb", "spec/import_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/table_spec.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "terminal-table.gemspec"]
|
14
14
|
s.homepage = %q{http://github.com/visionmedia/terminal-table}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Terminal-table", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terminal-table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-07 00:00:00.000000000Z
|
14
14
|
dependencies: []
|
15
15
|
description: Simple, feature rich ascii table generation library
|
16
16
|
email: tj@vision-media.ca
|
@@ -21,11 +21,13 @@ extra_rdoc_files:
|
|
21
21
|
- lib/terminal-table.rb
|
22
22
|
- lib/terminal-table/cell.rb
|
23
23
|
- lib/terminal-table/core_ext.rb
|
24
|
-
- lib/terminal-table/heading.rb
|
25
24
|
- lib/terminal-table/import.rb
|
26
25
|
- lib/terminal-table/table.rb
|
27
26
|
- lib/terminal-table/table_helper.rb
|
28
27
|
- lib/terminal-table/version.rb
|
28
|
+
- lib/terminal-table/row.rb
|
29
|
+
- lib/terminal-table/separator.rb
|
30
|
+
- lib/terminal-table/style.rb
|
29
31
|
- tasks/docs.rake
|
30
32
|
- tasks/gemspec.rake
|
31
33
|
- tasks/spec.rake
|
@@ -39,11 +41,13 @@ files:
|
|
39
41
|
- lib/terminal-table.rb
|
40
42
|
- lib/terminal-table/cell.rb
|
41
43
|
- lib/terminal-table/core_ext.rb
|
42
|
-
- lib/terminal-table/heading.rb
|
43
44
|
- lib/terminal-table/import.rb
|
44
45
|
- lib/terminal-table/table.rb
|
45
46
|
- lib/terminal-table/table_helper.rb
|
46
47
|
- lib/terminal-table/version.rb
|
48
|
+
- lib/terminal-table/row.rb
|
49
|
+
- lib/terminal-table/separator.rb
|
50
|
+
- lib/terminal-table/style.rb
|
47
51
|
- spec/cell_spec.rb
|
48
52
|
- spec/core_ext_spec.rb
|
49
53
|
- spec/import_spec.rb
|