terminal-table 1.4.5 → 1.5.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 +7 -0
- data/History.rdoc +48 -54
- data/Manifest +0 -4
- data/README.rdoc +240 -240
- data/Rakefile +14 -14
- data/Todo.rdoc +13 -13
- data/examples/examples.rb +83 -80
- data/lib/terminal-table.rb +2 -2
- data/lib/terminal-table/cell.rb +7 -9
- data/lib/terminal-table/import.rb +4 -4
- data/lib/terminal-table/table.rb +14 -8
- data/lib/terminal-table/table_helper.rb +9 -9
- data/lib/terminal-table/version.rb +1 -1
- data/spec/cell_spec.rb +12 -6
- data/spec/import_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -8
- data/spec/table_spec.rb +54 -7
- data/tasks/docs.rake +12 -12
- data/tasks/gemspec.rake +2 -2
- data/tasks/spec.rake +24 -24
- data/terminal-table.gemspec +6 -5
- metadata +53 -63
- data/lib/terminal-table/core_ext.rb +0 -8
- data/lib/terminal-table/row.rb +0 -48
- data/lib/terminal-table/separator.rb +0 -14
- data/lib/terminal-table/style.rb +0 -61
- data/spec/core_ext_spec.rb +0 -18
- data/spec/spec.opts +0 -1
data/spec/table_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
module Terminal
|
5
5
|
describe Table do
|
6
6
|
before :each do
|
7
7
|
@table = Table.new
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should select columns" do
|
11
11
|
@table << ['foo', 'bar']
|
12
12
|
@table << ['big foo', 'big foo bar']
|
@@ -137,6 +137,25 @@ module Terminal
|
|
137
137
|
EOF
|
138
138
|
end
|
139
139
|
|
140
|
+
|
141
|
+
it "should render default alignment properly" do
|
142
|
+
@table.headings = ['Char', 'Num']
|
143
|
+
@table << ['a', 1]
|
144
|
+
@table << ['b', 2]
|
145
|
+
@table << ['c', 3]
|
146
|
+
@table.style.width = 21
|
147
|
+
@table.style.alignment = :right
|
148
|
+
@table.render.should == <<-EOF.deindent
|
149
|
+
+---------+---------+
|
150
|
+
| Char | Num |
|
151
|
+
+---------+---------+
|
152
|
+
| a | 1 |
|
153
|
+
| b | 2 |
|
154
|
+
| c | 3 |
|
155
|
+
+---------+---------+
|
156
|
+
EOF
|
157
|
+
end
|
158
|
+
|
140
159
|
it "should render width properly" do
|
141
160
|
@table.headings = ['Char', 'Num']
|
142
161
|
@table << ['a', 1]
|
@@ -154,6 +173,16 @@ module Terminal
|
|
154
173
|
EOF
|
155
174
|
end
|
156
175
|
|
176
|
+
it "should raise an error if the table width exceeds style width" do
|
177
|
+
@table.headings = ['Char', 'Num']
|
178
|
+
@table << ['a', 1]
|
179
|
+
@table << ['b', 2]
|
180
|
+
@table << ['c', 3]
|
181
|
+
@table << ['d', 'x' * 22]
|
182
|
+
@table.style.width = 21
|
183
|
+
expect { @table.render }.to raise_error "Table width exceeds wanted width of 21 characters."
|
184
|
+
end
|
185
|
+
|
157
186
|
it "should render title properly" do
|
158
187
|
@table.title = "Title"
|
159
188
|
@table.headings = ['Char', 'Num']
|
@@ -254,6 +283,24 @@ module Terminal
|
|
254
283
|
EOF
|
255
284
|
end
|
256
285
|
|
286
|
+
it "should render multi-row headings properly" do
|
287
|
+
@table.headings = [['Char', 'Num'], [{ :value => "2nd heading", :colspan => 2 }]]
|
288
|
+
@table << ['a', 1]
|
289
|
+
@table << ['b', 2]
|
290
|
+
@table << ['c', 3]
|
291
|
+
@table.render.should == <<-EOF.deindent
|
292
|
+
+------+------+
|
293
|
+
| Char | Num |
|
294
|
+
+------+------+
|
295
|
+
| 2nd heading |
|
296
|
+
+------+------+
|
297
|
+
| a | 1 |
|
298
|
+
| b | 2 |
|
299
|
+
| c | 3 |
|
300
|
+
+------+------+
|
301
|
+
EOF
|
302
|
+
end
|
303
|
+
|
257
304
|
it "should allows a hash of options for creation" do
|
258
305
|
headings = ['Char', 'Num']
|
259
306
|
rows = [['a', 1], ['b', 2], ['c', 3]]
|
@@ -324,7 +371,7 @@ module Terminal
|
|
324
371
|
# it "should be equal with two empty tables" do
|
325
372
|
# table_one = Table.new
|
326
373
|
# table_two = Table.new
|
327
|
-
#
|
374
|
+
#
|
328
375
|
# table_one.should == table_two
|
329
376
|
# table_two.should == table_one
|
330
377
|
# end
|
@@ -448,7 +495,7 @@ module Terminal
|
|
448
495
|
@table.headings = ['name', { :value => 'values', :alignment => :right, :colspan => 3}]
|
449
496
|
@table.headings = ['name', { :value => 'values', :colspan => 3}]
|
450
497
|
@table.rows = [['a', 1, 2, 3], ['b', 4, 5, 6], ['c', 7, 8, 9]]
|
451
|
-
|
498
|
+
|
452
499
|
@table.render.should == <<-EOF.deindent
|
453
500
|
+------+---+---+---+
|
454
501
|
| name | values |
|
@@ -459,7 +506,7 @@ module Terminal
|
|
459
506
|
+------+---+---+---+
|
460
507
|
EOF
|
461
508
|
end
|
462
|
-
|
509
|
+
|
463
510
|
it "should handle multiple colspan" do
|
464
511
|
@table.headings = [
|
465
512
|
'name',
|
@@ -486,7 +533,7 @@ module Terminal
|
|
486
533
|
+--------+----+----+-------+-------+-----+-----+
|
487
534
|
EOF
|
488
535
|
end
|
489
|
-
|
536
|
+
|
490
537
|
it "should render a table with only X cell borders" do
|
491
538
|
@table.style = {:border_x => "-", :border_y => "", :border_i => ""}
|
492
539
|
|
@@ -504,7 +551,7 @@ module Terminal
|
|
504
551
|
---------------
|
505
552
|
EOF
|
506
553
|
end
|
507
|
-
|
554
|
+
|
508
555
|
it "should render a table without cell borders" do
|
509
556
|
@table.style = {:border_x => "", :border_y => "", :border_i => ""}
|
510
557
|
|
data/tasks/docs.rake
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
namespace :docs do
|
3
|
-
|
4
|
-
desc 'Remove rdoc products'
|
5
|
-
task :remove => [:clobber_docs]
|
6
|
-
|
7
|
-
desc 'Build docs, and open in browser for viewing (specify BROWSER)'
|
8
|
-
task :open => [:docs] do
|
9
|
-
browser = ENV["BROWSER"] || "safari"
|
10
|
-
sh "open -a #{browser} doc/index.html"
|
11
|
-
end
|
12
|
-
|
1
|
+
|
2
|
+
namespace :docs do
|
3
|
+
|
4
|
+
desc 'Remove rdoc products'
|
5
|
+
task :remove => [:clobber_docs]
|
6
|
+
|
7
|
+
desc 'Build docs, and open in browser for viewing (specify BROWSER)'
|
8
|
+
task :open => [:docs] do
|
9
|
+
browser = ENV["BROWSER"] || "safari"
|
10
|
+
sh "open -a #{browser} doc/index.html"
|
11
|
+
end
|
12
|
+
|
13
13
|
end
|
data/tasks/gemspec.rake
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
desc 'Build gemspec file'
|
1
|
+
|
2
|
+
desc 'Build gemspec file'
|
3
3
|
task :gemspec => [:build_gemspec]
|
data/tasks/spec.rake
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
|
2
|
-
require 'spec/rake/spectask'
|
3
|
-
|
4
|
-
desc "Run all specifications"
|
5
|
-
Spec::Rake::SpecTask.new(:spec) do |t|
|
6
|
-
t.libs << "lib"
|
7
|
-
t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
|
8
|
-
end
|
9
|
-
|
10
|
-
namespace :spec do
|
11
|
-
|
12
|
-
desc "Run all specifications verbosely"
|
13
|
-
Spec::Rake::SpecTask.new(:verbose) do |t|
|
14
|
-
t.libs << "lib"
|
15
|
-
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
16
|
-
end
|
17
|
-
|
18
|
-
desc "Run specific specification verbosely (specify SPEC)"
|
19
|
-
Spec::Rake::SpecTask.new(:select) do |t|
|
20
|
-
t.libs << "lib"
|
21
|
-
t.spec_files = [ENV["SPEC"]]
|
22
|
-
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
23
|
-
end
|
24
|
-
|
1
|
+
|
2
|
+
require 'spec/rake/spectask'
|
3
|
+
|
4
|
+
desc "Run all specifications"
|
5
|
+
Spec::Rake::SpecTask.new(:spec) do |t|
|
6
|
+
t.libs << "lib"
|
7
|
+
t.spec_opts = ["--color", "--require", "spec/spec_helper.rb"]
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :spec do
|
11
|
+
|
12
|
+
desc "Run all specifications verbosely"
|
13
|
+
Spec::Rake::SpecTask.new(:verbose) do |t|
|
14
|
+
t.libs << "lib"
|
15
|
+
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Run specific specification verbosely (specify SPEC)"
|
19
|
+
Spec::Rake::SpecTask.new(:select) do |t|
|
20
|
+
t.libs << "lib"
|
21
|
+
t.spec_files = [ENV["SPEC"]]
|
22
|
+
t.spec_opts = ["--color", "--format", "specdoc", "--require", "spec/spec_helper.rb"]
|
23
|
+
end
|
24
|
+
|
25
25
|
end
|
data/terminal-table.gemspec
CHANGED
@@ -2,23 +2,24 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{terminal-table}
|
5
|
-
s.version = "1.
|
5
|
+
s.version = "1.5.0"
|
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{
|
9
|
+
s.date = %q{2011-10-13}
|
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/
|
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/
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/table_helper.rb", "lib/terminal-table/version.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/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/table_helper.rb", "lib/terminal-table/version.rb", "spec/cell_spec.rb", "spec/import_spec.rb", "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
|
+
s.license = %q{MIT}
|
15
16
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Terminal-table", "--main", "README.rdoc"]
|
16
17
|
s.require_paths = ["lib"]
|
17
18
|
s.rubyforge_project = %q{terminal-table}
|
18
19
|
s.rubygems_version = %q{1.3.5}
|
19
20
|
s.summary = %q{Simple, feature rich ascii table generation library}
|
20
21
|
|
21
|
-
if s.respond_to? :specification_version
|
22
|
+
if s.respond_to? :specification_version then
|
22
23
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
24
|
s.specification_version = 3
|
24
25
|
|
metadata
CHANGED
@@ -1,35 +1,32 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
1
|
+
--- !ruby/object:Gem::Specification
|
4
2
|
name: terminal-table
|
5
|
-
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2012-03-15 00:00:00 +00:00
|
8
|
-
summary: Simple, feature rich ascii table generation library
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: tj@vision-media.ca
|
12
|
-
homepage: http://github.com/visionmedia/terminal-table
|
13
|
-
rubyforge_project: terminal-table
|
14
|
-
description: Simple, feature rich ascii table generation library
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.0
|
25
5
|
platform: ruby
|
26
|
-
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
|
-
authors:
|
6
|
+
authors:
|
30
7
|
- TJ Holowaychuk
|
31
8
|
- Scott J. Goldman
|
32
|
-
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Simple, feature rich ascii table generation library
|
15
|
+
email: tj@vision-media.ca
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.rdoc
|
20
|
+
- lib/terminal-table.rb
|
21
|
+
- lib/terminal-table/cell.rb
|
22
|
+
- lib/terminal-table/import.rb
|
23
|
+
- lib/terminal-table/table.rb
|
24
|
+
- lib/terminal-table/table_helper.rb
|
25
|
+
- lib/terminal-table/version.rb
|
26
|
+
- tasks/docs.rake
|
27
|
+
- tasks/gemspec.rake
|
28
|
+
- tasks/spec.rake
|
29
|
+
files:
|
33
30
|
- History.rdoc
|
34
31
|
- Manifest
|
35
32
|
- README.rdoc
|
@@ -38,53 +35,46 @@ files:
|
|
38
35
|
- examples/examples.rb
|
39
36
|
- lib/terminal-table.rb
|
40
37
|
- lib/terminal-table/cell.rb
|
41
|
-
- lib/terminal-table/core_ext.rb
|
42
38
|
- lib/terminal-table/import.rb
|
43
39
|
- lib/terminal-table/table.rb
|
44
40
|
- lib/terminal-table/table_helper.rb
|
45
41
|
- lib/terminal-table/version.rb
|
46
|
-
- lib/terminal-table/row.rb
|
47
|
-
- lib/terminal-table/separator.rb
|
48
|
-
- lib/terminal-table/style.rb
|
49
42
|
- spec/cell_spec.rb
|
50
|
-
- spec/core_ext_spec.rb
|
51
43
|
- spec/import_spec.rb
|
52
|
-
- spec/spec.opts
|
53
44
|
- spec/spec_helper.rb
|
54
45
|
- spec/table_spec.rb
|
55
46
|
- tasks/docs.rake
|
56
47
|
- tasks/gemspec.rake
|
57
48
|
- tasks/spec.rake
|
58
49
|
- terminal-table.gemspec
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
50
|
+
homepage: http://github.com/visionmedia/terminal-table
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options:
|
56
|
+
- "--line-numbers"
|
57
|
+
- "--inline-source"
|
58
|
+
- "--title"
|
65
59
|
- Terminal-table
|
66
|
-
- --main
|
60
|
+
- "--main"
|
67
61
|
- README.rdoc
|
68
|
-
|
69
|
-
-
|
70
|
-
|
71
|
-
|
72
|
-
-
|
73
|
-
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
|
80
|
-
- tasks/docs.rake
|
81
|
-
- tasks/gemspec.rake
|
82
|
-
- tasks/spec.rake
|
83
|
-
executables: []
|
84
|
-
|
85
|
-
extensions: []
|
86
|
-
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1.2'
|
87
74
|
requirements: []
|
88
|
-
|
89
|
-
|
90
|
-
|
75
|
+
rubyforge_project: terminal-table
|
76
|
+
rubygems_version: 2.4.8
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Simple, feature rich ascii table generation library
|
80
|
+
test_files: []
|
data/lib/terminal-table/row.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
module Terminal
|
2
|
-
class Table
|
3
|
-
class Row
|
4
|
-
|
5
|
-
##
|
6
|
-
# Row cells
|
7
|
-
|
8
|
-
attr_reader :cells
|
9
|
-
|
10
|
-
attr_reader :table
|
11
|
-
|
12
|
-
##
|
13
|
-
# Initialize with _width_ and _options_.
|
14
|
-
|
15
|
-
def initialize table, array = []
|
16
|
-
@cell_index = 0
|
17
|
-
@table = table
|
18
|
-
@cells = []
|
19
|
-
array.each { |item| self << item }
|
20
|
-
end
|
21
|
-
|
22
|
-
def add_cell item
|
23
|
-
options = item.is_a?(Hash) ? item : {:value => item}
|
24
|
-
cell = Cell.new(options.merge(:index => @cell_index, :table => @table))
|
25
|
-
@cell_index += cell.colspan
|
26
|
-
@cells << cell
|
27
|
-
end
|
28
|
-
alias << add_cell
|
29
|
-
|
30
|
-
def [] index
|
31
|
-
cells[index]
|
32
|
-
end
|
33
|
-
|
34
|
-
def height
|
35
|
-
cells.map { |c| c.lines.count }.max
|
36
|
-
end
|
37
|
-
|
38
|
-
def render
|
39
|
-
y = @table.style.border_y
|
40
|
-
(0...height).to_a.map do |line|
|
41
|
-
y + cells.map do |cell|
|
42
|
-
cell.render(line)
|
43
|
-
end.join(y) + y
|
44
|
-
end.join("\n")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Terminal
|
2
|
-
class Table
|
3
|
-
class Separator < Row
|
4
|
-
|
5
|
-
def render
|
6
|
-
arr_x = (0...@table.number_of_columns).to_a.map do |i|
|
7
|
-
@table.style.border_x * (@table.column_width(i) + @table.cell_padding)
|
8
|
-
end
|
9
|
-
border_i = @table.style.border_i
|
10
|
-
border_i + arr_x.join(border_i) + border_i
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|