terminal-table 1.5.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 690e92a400d543a8d7b55922fda25db11d1aa46d
4
- data.tar.gz: 3b71abe9af27c9dc2360a7c3bd9651b00ff9de0d
3
+ metadata.gz: 313963c2be91f08803b78b1d933955c2a23b8a0a
4
+ data.tar.gz: db59f26e5ea165487fdd1c43f0bf39c1a9203476
5
5
  SHA512:
6
- metadata.gz: a5cae8343447741182f569b19661341ee1b01daf5ac8ca20dea290a1e66aa8dedb00215cd9e67ea55cad9b1e3bcbf8b1dad27533c069b689033a184ad376f269
7
- data.tar.gz: 78cd38cbb66f3c98b74cdc869a30447da2751d06baf4bd853206e7ecaf4e7444ff4c286a0b93c64fc3fbe4c741033c9aaec6362e98a1f354eb69926288692c5f
6
+ metadata.gz: 8fe9f4508ffd90a2e57c2629bef2341692e80a476db60eafffabd35e2710a4c8e0107767c1c5a68537178ae5369c8e6436729c0d131c09b009290be422415390
7
+ data.tar.gz: 2f88a22636edfe84955c152d6f60e65d9d32a662da5faca63d4fe3cb9c45896371ca778b01c3952aa592a0fb888b8da7e100f94bcfefea25c5a95a204d0d9437
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ pkg
3
+ tmp
4
+ *.cache
5
+ doc
6
+ Gemfile.lock
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.8.7@terminal-table --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in test-gem.gemspec
4
+ gemspec
data/Manifest CHANGED
@@ -1,5 +1,5 @@
1
+ Gemfile
1
2
  History.rdoc
2
- Manifest
3
3
  README.rdoc
4
4
  Rakefile
5
5
  Todo.rdoc
@@ -7,14 +7,21 @@ examples/examples.rb
7
7
  lib/terminal-table.rb
8
8
  lib/terminal-table/cell.rb
9
9
  lib/terminal-table/import.rb
10
+ lib/terminal-table/row.rb
11
+ lib/terminal-table/separator.rb
12
+ lib/terminal-table/style.rb
10
13
  lib/terminal-table/table.rb
11
14
  lib/terminal-table/table_helper.rb
12
15
  lib/terminal-table/version.rb
13
16
  spec/cell_spec.rb
14
- spec/import_spec.rb
17
+ spec/row_spec.rb
15
18
  spec/spec_helper.rb
19
+ spec/table_helper_spec.rb
16
20
  spec/table_spec.rb
17
21
  tasks/docs.rake
18
22
  tasks/gemspec.rake
19
23
  tasks/spec.rake
20
24
  terminal-table.gemspec
25
+ terminal-table.sublime-project
26
+ terminal-table.sublime-workspace
27
+ Manifest
data/Rakefile CHANGED
@@ -1,15 +1,9 @@
1
-
2
- require 'rubygems'
3
- require 'rake'
4
- require 'echoe'
5
- require './lib/terminal-table.rb'
6
-
7
- Echoe.new("terminal-table", Terminal::Table::VERSION) do |p|
8
- p.author = "TJ Holowaychuk"
9
- p.email = "tj@vision-media.ca"
10
- p.summary = "Simple, feature rich ascii table generation library"
11
- p.url = "http://github.com/visionmedia/terminal-table"
12
- p.runtime_dependencies = []
13
- end
14
-
15
- Dir['tasks/**/*.rake'].sort.each { |lib| load lib }
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run specs"
4
+ task :spec do
5
+ sh "bundle exec rspec -f progress"
6
+ end
7
+
8
+ desc "Default: Run specs"
9
+ task :default => [:spec]
@@ -21,7 +21,6 @@
21
21
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  #++
23
23
 
24
- $:.unshift File.dirname(__FILE__)
25
- %w(version table cell row separator style table_helper).each do |file|
24
+ %w(cell row separator style table table_helper version).each do |file|
26
25
  require "terminal-table/#{file}"
27
26
  end
@@ -1,4 +1 @@
1
-
2
- require 'terminal-table'
3
-
4
- include Terminal::Table::TableHelper
1
+ include Terminal::Table::TableHelper
@@ -0,0 +1,48 @@
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
@@ -0,0 +1,14 @@
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
@@ -0,0 +1,62 @@
1
+
2
+ module Terminal
3
+ class Table
4
+ # A Style object holds all the formatting information for a Table object
5
+ #
6
+ # To create a table with a certain style, use either the constructor
7
+ # option <tt>:style</tt>, the Table#style object or the Table#style= method
8
+ #
9
+ # All these examples have the same effect:
10
+ #
11
+ # # by constructor
12
+ # @table = Table.new(:style => {:padding_left => 2, :width => 40})
13
+ #
14
+ # # by object
15
+ # @table.style.padding_left = 2
16
+ # @table.style.width = 40
17
+ #
18
+ # # by method
19
+ # @table.style = {:padding_left => 2, :width => 40}
20
+ #
21
+ # To set a default style for all tables created afterwards use Style.defaults=
22
+ #
23
+ # Terminal::Table::Style.defaults = {:width => 80}
24
+ #
25
+ class Style
26
+ @@defaults = {
27
+ :border_x => "-", :border_y => "|", :border_i => "+",
28
+ :padding_left => 1, :padding_right => 1,
29
+ :width => nil, :alignment => nil
30
+ }
31
+
32
+ attr_accessor :border_x
33
+ attr_accessor :border_y
34
+ attr_accessor :border_i
35
+
36
+ attr_accessor :padding_left
37
+ attr_accessor :padding_right
38
+
39
+ attr_accessor :width
40
+ attr_accessor :alignment
41
+
42
+
43
+ def initialize options = {}
44
+ apply self.class.defaults.merge(options)
45
+ end
46
+
47
+ def apply options
48
+ options.each { |m, v| __send__ "#{m}=", v }
49
+ end
50
+
51
+ class << self
52
+ def defaults
53
+ @@defaults
54
+ end
55
+
56
+ def defaults= options
57
+ @@defaults = defaults.merge(options)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -1,6 +1,5 @@
1
-
2
1
  module Terminal
3
2
  class Table
4
- VERSION = '1.5.0'
3
+ VERSION = '1.5.1'
5
4
  end
6
5
  end
@@ -1,31 +1,24 @@
1
- # -*- encoding: utf-8 -*-
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'terminal-table/version'
2
5
 
3
- Gem::Specification.new do |s|
4
- s.name = %q{terminal-table}
5
- s.version = "1.5.0"
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "terminal-table"
8
+ spec.version = Terminal::Table::VERSION
9
+ spec.authors = ["TJ Holowaychuk", "Scott J. Goldman"]
10
+ spec.email = ["tj@vision-media.ca"]
6
11
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["TJ Holowaychuk", "Scott J. Goldman"]
9
- s.date = %q{2011-10-13}
10
- s.description = %q{Simple, feature rich ascii table generation library}
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/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
- s.homepage = %q{http://github.com/visionmedia/terminal-table}
15
- s.license = %q{MIT}
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Terminal-table", "--main", "README.rdoc"]
17
- s.require_paths = ["lib"]
18
- s.rubyforge_project = %q{terminal-table}
19
- s.rubygems_version = %q{1.3.5}
20
- s.summary = %q{Simple, feature rich ascii table generation library}
12
+ spec.summary = "Simple, feature rich ascii table generation library"
13
+ spec.homepage = "https://github.com/tj/terminal-table"
14
+ spec.license = "MIT"
21
15
 
22
- if s.respond_to? :specification_version then
23
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 3
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
25
18
 
26
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
- else
28
- end
29
- else
30
- end
19
+ spec.add_development_dependency "bundler", "~> 1.10"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rspec", ">= 3.0"
22
+ spec.add_development_dependency "term-ansicolor"
23
+ spec.add_development_dependency "pry"
31
24
  end
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.5.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,24 +9,88 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
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
12
+ date: 2015-06-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.10'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.10'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '3.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: term-ansicolor
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: pry
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ description:
85
+ email:
86
+ - tj@vision-media.ca
16
87
  executables: []
17
88
  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
89
+ extra_rdoc_files: []
29
90
  files:
91
+ - ".gitignore"
92
+ - ".rvmrc"
93
+ - Gemfile
30
94
  - History.rdoc
31
95
  - Manifest
32
96
  - README.rdoc
@@ -36,29 +100,19 @@ files:
36
100
  - lib/terminal-table.rb
37
101
  - lib/terminal-table/cell.rb
38
102
  - lib/terminal-table/import.rb
103
+ - lib/terminal-table/row.rb
104
+ - lib/terminal-table/separator.rb
105
+ - lib/terminal-table/style.rb
39
106
  - lib/terminal-table/table.rb
40
107
  - lib/terminal-table/table_helper.rb
41
108
  - lib/terminal-table/version.rb
42
- - spec/cell_spec.rb
43
- - spec/import_spec.rb
44
- - spec/spec_helper.rb
45
- - spec/table_spec.rb
46
- - tasks/docs.rake
47
- - tasks/gemspec.rake
48
- - tasks/spec.rake
49
109
  - terminal-table.gemspec
50
- homepage: http://github.com/visionmedia/terminal-table
110
+ homepage: https://github.com/tj/terminal-table
51
111
  licenses:
52
112
  - MIT
53
113
  metadata: {}
54
114
  post_install_message:
55
- rdoc_options:
56
- - "--line-numbers"
57
- - "--inline-source"
58
- - "--title"
59
- - Terminal-table
60
- - "--main"
61
- - README.rdoc
115
+ rdoc_options: []
62
116
  require_paths:
63
117
  - lib
64
118
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -70,11 +124,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
124
  requirements:
71
125
  - - ">="
72
126
  - !ruby/object:Gem::Version
73
- version: '1.2'
127
+ version: '0'
74
128
  requirements: []
75
- rubyforge_project: terminal-table
129
+ rubyforge_project:
76
130
  rubygems_version: 2.4.8
77
131
  signing_key:
78
- specification_version: 3
132
+ specification_version: 4
79
133
  summary: Simple, feature rich ascii table generation library
80
134
  test_files: []
@@ -1,60 +0,0 @@
1
- require 'rubygems'
2
- require 'term/ansicolor'
3
-
4
- class String; include Term::ANSIColor; end
5
-
6
- require 'spec_helper'
7
-
8
- describe Terminal::Table do
9
- Cell = Terminal::Table::Cell
10
-
11
- it "should default alignment to the left" do
12
- cell = Cell.new :value => 'foo', :table => Terminal::Table.new, :index => 0
13
- cell.value.should == 'foo'
14
- cell.alignment.should == :left
15
- end
16
-
17
- it "should allow overriding of alignment" do
18
- cell = Cell.new :value => 'foo', :alignment => :center, :table => Terminal::Table.new, :index => 0
19
- cell.value.should == 'foo'
20
- cell.alignment.should == :center
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 => "barrissimo\n"+"foo".yellow, :table => Terminal::Table.new, :index => 0
33
- cell.value.should == "barrissimo\n"+"foo".yellow
34
- cell.lines.should == ['barrissimo','foo'.yellow]
35
- cell.value_for_column_width_recalc.should == 'barrissimo'
36
- cell.render(0).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
-
54
- it "should not ignore pipe characters" do
55
- cell = Cell.new :value => "f|o|o", :table => Terminal::Table.new, :index => 0
56
- cell.value.should == "f|o|o"
57
- cell.value_for_column_width_recalc.should == 'f|o|o'
58
- cell.render.should == " f|o|o "
59
- end
60
- end
@@ -1,11 +0,0 @@
1
-
2
- require 'spec_helper'
3
- require "terminal-table/import"
4
-
5
- describe Object do
6
- describe "#table" do
7
- it "should allow creation of a terminal table" do
8
- table(['foo', 'bar'], ['a', 'b'], [1, 2]).should be_instance_of(Terminal::Table)
9
- end
10
- end
11
- end
@@ -1,8 +0,0 @@
1
-
2
- require File.dirname(__FILE__) + '/../lib/terminal-table'
3
-
4
- class String
5
- def deindent
6
- strip.gsub(/^ */, '')
7
- end
8
- end
@@ -1,572 +0,0 @@
1
-
2
- require 'spec_helper'
3
-
4
- module Terminal
5
- describe Table do
6
- before :each do
7
- @table = Table.new
8
- end
9
-
10
- it "should select columns" do
11
- @table << ['foo', 'bar']
12
- @table << ['big foo', 'big foo bar']
13
- @table.column(1).should == ['bar', 'big foo bar']
14
- end
15
-
16
- it "should select the column with headings at an index" do
17
- @table << [1,2,3]
18
- @table << [4,5,6]
19
- @table.column_with_headings(2).should == [3,6]
20
- end
21
-
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
-
27
- it "should account for the colspan when selecting columns" do
28
- @table << [1,2,3]
29
- @table << [{:value => "4,5", :colspan => 2}, 6]
30
- @table.column_with_headings(0).should == [1,"4,5"]
31
- @table.column_with_headings(1).should == [2,"4,5"]
32
- @table.column_with_headings(2).should == [3,6]
33
- end
34
-
35
- it "should render tables with colspan properly" do
36
- @table << [1,2,3]
37
- @table << [4,5,6]
38
- @table << [{:value => "7", :colspan => 2}, 88]
39
- @table.render.should == <<-EOF.deindent
40
- +---+---+----+
41
- | 1 | 2 | 3 |
42
- | 4 | 5 | 6 |
43
- | 7 | 88 |
44
- +---+---+----+
45
- EOF
46
- end
47
-
48
- it "should count columns" do
49
- @table << [1, 2, 3]
50
- @table.number_of_columns.should == 3
51
- end
52
-
53
- it "should iterate columns" do
54
- @table << [1, 2, 3]
55
- @table << [4, 5, 6]
56
- @table.columns.should == [[1, 4], [2, 5], [3, 6]]
57
- end
58
-
59
- it "should select columns" do
60
- @table.headings = ['one', 'two']
61
- @table << ['foo', 'bar']
62
- @table << ['big foo', 'big foo bar']
63
- @table.column(1).should == ['bar', 'big foo bar']
64
- end
65
-
66
- it "should select columns when using hashes" do
67
- @table.headings = ['one', 'two']
68
- @table.rows = [[{ :value => 'a', :align => :left }, 1], ['b', 2], ['c', 3]]
69
- @table.column(0).should == ['a', 'b', 'c']
70
- end
71
-
72
- it "should find column length" do
73
- @table << ['foo', 'bar', 'a']
74
- @table << ['big foo', 'big foo bar']
75
- @table.column_width(1).should == 11
76
- end
77
-
78
- it "should find column length with headings" do
79
- @table.headings = ['one', 'super long heading']
80
- @table << ['foo', 'bar', 'a']
81
- @table << ['big foo', 'big foo bar']
82
- @table.column_width(1).should == 18
83
- end
84
-
85
- it "should render separators" do
86
- @table.headings = ['Char', 'Num']
87
- @table << ['a', 1]
88
- separator = Terminal::Table::Separator.new(@table)
89
- separator.render.should == '+------+-----+'
90
- end
91
-
92
- it "should add separator" do
93
- @table << ['a', 1]
94
- @table.add_separator
95
- @table << ['b', 2]
96
- @table.rows.size.should == 2
97
- end
98
-
99
- it "should render an empty table properly" do
100
- @table.render.should == <<-EOF.deindent
101
- ++
102
- ++
103
- EOF
104
- end
105
-
106
- it "should render properly" do
107
- @table.headings = ['Char', 'Num']
108
- @table << ['a', 1]
109
- @table << ['b', 2]
110
- @table << ['c', 3]
111
- @table.render.should == <<-EOF.deindent
112
- +------+-----+
113
- | Char | Num |
114
- +------+-----+
115
- | a | 1 |
116
- | b | 2 |
117
- | c | 3 |
118
- +------+-----+
119
- EOF
120
- end
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
-
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
-
159
- it "should render width properly" do
160
- @table.headings = ['Char', 'Num']
161
- @table << ['a', 1]
162
- @table << ['b', 2]
163
- @table << ['c', 3]
164
- @table.style.width = 21
165
- @table.render.should == <<-EOF.deindent
166
- +---------+---------+
167
- | Char | Num |
168
- +---------+---------+
169
- | a | 1 |
170
- | b | 2 |
171
- | c | 3 |
172
- +---------+---------+
173
- EOF
174
- end
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
-
186
- it "should render title properly" do
187
- @table.title = "Title"
188
- @table.headings = ['Char', 'Num']
189
- @table << ['a', 1]
190
- @table << ['b', 2]
191
- @table << ['c', 3]
192
- @table.render.should == <<-EOF.deindent
193
- +------+-----+
194
- | Title |
195
- +------+-----+
196
- | Char | Num |
197
- +------+-----+
198
- | a | 1 |
199
- | b | 2 |
200
- | c | 3 |
201
- +------+-----+
202
- EOF
203
- end
204
-
205
- it "should render properly without headings" do
206
- @table << ['a', 1]
207
- @table << ['b', 2]
208
- @table << ['c', 3]
209
- @table.render.should == <<-EOF.deindent
210
- +---+---+
211
- | a | 1 |
212
- | b | 2 |
213
- | c | 3 |
214
- +---+---+
215
- EOF
216
- end
217
-
218
- it "should render separators" do
219
- @table.headings = ['Char', 'Num']
220
- @table << ['a', 1]
221
- @table << ['b', 2]
222
- @table.add_separator
223
- @table << ['c', 3]
224
- @table.render.should == <<-EOF.deindent
225
- +------+-----+
226
- | Char | Num |
227
- +------+-----+
228
- | a | 1 |
229
- | b | 2 |
230
- +------+-----+
231
- | c | 3 |
232
- +------+-----+
233
- EOF
234
- end
235
-
236
- it "should align columns with separators" do
237
- @table.headings = ['Char', 'Num']
238
- @table << ['a', 1]
239
- @table << ['b', 2]
240
- @table.add_separator
241
- @table << ['c', 3]
242
- @table.align_column 1, :right
243
- @table.render.should == <<-EOF.deindent
244
- +------+-----+
245
- | Char | Num |
246
- +------+-----+
247
- | a | 1 |
248
- | b | 2 |
249
- +------+-----+
250
- | c | 3 |
251
- +------+-----+
252
- EOF
253
- end
254
-
255
-
256
- it "should render properly using block syntax" do
257
- table = Terminal::Table.new do |t|
258
- t << ['a', 1]
259
- t << ['b', 2]
260
- t << ['c', 3]
261
- end
262
- table.render.should == <<-EOF.deindent
263
- +---+---+
264
- | a | 1 |
265
- | b | 2 |
266
- | c | 3 |
267
- +---+---+
268
- EOF
269
- end
270
-
271
- it "should render properly using instance_eval block syntax" do
272
- table = Terminal::Table.new do
273
- add_row ['a', 1]
274
- add_row ['b', 2]
275
- add_row ['c', 3]
276
- end
277
- table.render.should == <<-EOF.deindent
278
- +---+---+
279
- | a | 1 |
280
- | b | 2 |
281
- | c | 3 |
282
- +---+---+
283
- EOF
284
- end
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
-
304
- it "should allows a hash of options for creation" do
305
- headings = ['Char', 'Num']
306
- rows = [['a', 1], ['b', 2], ['c', 3]]
307
- Terminal::Table.new(:rows => rows, :headings => headings).render.should == <<-EOF.deindent
308
- +------+-----+
309
- | Char | Num |
310
- +------+-----+
311
- | a | 1 |
312
- | b | 2 |
313
- | c | 3 |
314
- +------+-----+
315
- EOF
316
- end
317
-
318
- it "should flex for large cells" do
319
- @table.headings = ['Just some characters', 'Num']
320
- @table.rows = [['a', 1], ['b', 2], ['c', 3]]
321
- @table.render.should == <<-EOF.deindent
322
- +----------------------+-----+
323
- | Just some characters | Num |
324
- +----------------------+-----+
325
- | a | 1 |
326
- | b | 2 |
327
- | c | 3 |
328
- +----------------------+-----+
329
- EOF
330
- end
331
-
332
- it "should allow alignment of headings and cells" do
333
- @table.headings = ['Characters', {:value => 'Nums', :alignment => :right} ]
334
- @table << [{:value => 'a', :alignment => :center}, 1]
335
- @table << ['b', 222222222222222]
336
- @table << ['c', 3]
337
- @table.render.should == <<-EOF.deindent
338
- +------------+-----------------+
339
- | Characters | Nums |
340
- +------------+-----------------+
341
- | a | 1 |
342
- | b | 222222222222222 |
343
- | c | 3 |
344
- +------------+-----------------+
345
- EOF
346
-
347
- end
348
-
349
- it "should align columns, but allow specifics to remain" do
350
- @table.headings = ['Just some characters', 'Num']
351
- @table.rows = [[{:value => 'a', :alignment => :left}, 1], ['b', 2], ['c', 3]]
352
- @table.align_column 0, :center
353
- @table.align_column 1, :right
354
- @table.render.should == <<-EOF.deindent
355
- +----------------------+-----+
356
- | Just some characters | Num |
357
- +----------------------+-----+
358
- | a | 1 |
359
- | b | 2 |
360
- | c | 3 |
361
- +----------------------+-----+
362
- EOF
363
- end
364
-
365
- describe "#==" do
366
- it "should be equal to itself" do
367
- t = Table.new
368
- t.should == t
369
- end
370
-
371
- # it "should be equal with two empty tables" do
372
- # table_one = Table.new
373
- # table_two = Table.new
374
- #
375
- # table_one.should == table_two
376
- # table_two.should == table_one
377
- # end
378
-
379
- it "should not be equal with different headings" do
380
- table_one = Table.new
381
- table_two = Table.new
382
-
383
- table_one.headings << "a"
384
-
385
- table_one.should_not == table_two
386
- table_two.should_not == table_one
387
- end
388
-
389
- it "should not be equal with different rows" do
390
- table_one = Table.new
391
- table_two = Table.new
392
-
393
- table_one.should_not == table_two
394
- table_two.should_not == table_one
395
- end
396
-
397
- it "should not be equal if the other object does not respond_to? :headings" do
398
- table_one = Table.new
399
- table_two = Object.new
400
- table_two.stub!(:rows).and_return([])
401
- table_one.should_not == table_two
402
- end
403
-
404
- it "should not be equal if the other object does not respond_to? :rows" do
405
- table_one = Table.new
406
- table_two = Object.new
407
- table_two.stub!(:rows).and_return([])
408
- table_one.should_not == table_two
409
- end
410
- end
411
-
412
- it "should handle colspan inside heading" do
413
- @table.headings = ['one', { :value => 'two', :alignment => :center, :colspan => 2}]
414
- @table.rows = [['a', 1, 2], ['b', 3, 4], ['c', 3, 4]]
415
- @table.render.should == <<-EOF.deindent
416
- +-----+---+---+
417
- | one | two |
418
- +-----+---+---+
419
- | a | 1 | 2 |
420
- | b | 3 | 4 |
421
- | c | 3 | 4 |
422
- +-----+---+---+
423
- EOF
424
- end
425
-
426
- it "should handle colspan inside cells" do
427
- @table.headings = ['one', 'two', 'three']
428
- @table.rows = [['a', 1, 2], ['b', 3, 4], [{:value => "joined", :colspan => 2,:alignment => :center}, 'c']]
429
- @table.render.should == <<-EOF.deindent
430
- +-----+-----+-------+
431
- | one | two | three |
432
- +-----+-----+-------+
433
- | a | 1 | 2 |
434
- | b | 3 | 4 |
435
- | joined | c |
436
- +-----+-----+-------+
437
- EOF
438
- end
439
-
440
- it "should handle colspan inside cells regardless of colspan position" do
441
- @table.headings = ['one', 'two', 'three']
442
- @table.rows = [['a', 1, 2], ['b', 3, 4], ['c', {:value => "joined", :colspan => 2,:alignment => :center}]]
443
- @table.render.should == <<-EOF.deindent
444
- +-----+-----+-------+
445
- | one | two | three |
446
- +-----+-----+-------+
447
- | a | 1 | 2 |
448
- | b | 3 | 4 |
449
- | c | joined |
450
- +-----+-----+-------+
451
- EOF
452
- end
453
-
454
- it "should handle overflowing colspans" do
455
- @table.headings = ['one', 'two', 'three']
456
- @table.rows = [['a', 1, 2], ['b', 3, 4], ['c', {:value => "joined that is very very long", :colspan => 2,:alignment => :center}]]
457
- @table.render.should == <<-EOF.deindent
458
- +-----+---------------+---------------+
459
- | one | two | three |
460
- +-----+---------------+---------------+
461
- | a | 1 | 2 |
462
- | b | 3 | 4 |
463
- | c | joined that is very very long |
464
- +-----+---------------+---------------+
465
- EOF
466
- end
467
-
468
- it "should only increase column size for multi-column if it is unavoidable" do
469
- @table << [12345,2,3]
470
- @table << [{:value => 123456789, :colspan => 2}, 4]
471
- @table.render.should == <<-EOF.deindent
472
- +-------+---+---+
473
- | 12345 | 2 | 3 |
474
- | 123456789 | 4 |
475
- +-------+---+---+
476
- EOF
477
- end
478
-
479
-
480
- it "should handle colspan 1" do
481
- @table.headings = ['name', { :value => 'values', :colspan => 1}]
482
- @table.rows = [['a', 1], ['b', 4], ['c', 7]]
483
- @table.render.should == <<-EOF.deindent
484
- +------+--------+
485
- | name | values |
486
- +------+--------+
487
- | a | 1 |
488
- | b | 4 |
489
- | c | 7 |
490
- +------+--------+
491
- EOF
492
- end
493
-
494
- it "should handle big colspan" do
495
- @table.headings = ['name', { :value => 'values', :alignment => :right, :colspan => 3}]
496
- @table.headings = ['name', { :value => 'values', :colspan => 3}]
497
- @table.rows = [['a', 1, 2, 3], ['b', 4, 5, 6], ['c', 7, 8, 9]]
498
-
499
- @table.render.should == <<-EOF.deindent
500
- +------+---+---+---+
501
- | name | values |
502
- +------+---+---+---+
503
- | a | 1 | 2 | 3 |
504
- | b | 4 | 5 | 6 |
505
- | c | 7 | 8 | 9 |
506
- +------+---+---+---+
507
- EOF
508
- end
509
-
510
- it "should handle multiple colspan" do
511
- @table.headings = [
512
- 'name',
513
- { :value => 'Values', :alignment => :right, :colspan => 2},
514
- { :value => 'Other values', :alignment => :right, :colspan => 2},
515
- { :value => 'Column 3', :alignment => :right, :colspan => 2}
516
- ]
517
-
518
- 3.times do |row_index|
519
- row = ["row ##{row_index+1}"]
520
- 6.times do |i|
521
- row << row_index*6 + i
522
- end
523
- @table.add_row(row)
524
- end
525
-
526
- @table.render.should == <<-EOF.deindent
527
- +--------+----+----+-------+-------+-----+-----+
528
- | name | Values | Other values | Column 3 |
529
- +--------+----+----+-------+-------+-----+-----+
530
- | row #1 | 0 | 1 | 2 | 3 | 4 | 5 |
531
- | row #2 | 6 | 7 | 8 | 9 | 10 | 11 |
532
- | row #3 | 12 | 13 | 14 | 15 | 16 | 17 |
533
- +--------+----+----+-------+-------+-----+-----+
534
- EOF
535
- end
536
-
537
- it "should render a table with only X cell borders" do
538
- @table.style = {:border_x => "-", :border_y => "", :border_i => ""}
539
-
540
- @table.headings = ['name', { :value => 'values', :alignment => :right, :colspan => 3}]
541
- @table.headings = ['name', { :value => 'values', :colspan => 3}]
542
- @table.rows = [['a', 1, 2, 3], ['b', 4, 5, 6], ['c', 7, 8, 9]]
543
-
544
- @table.render.should == <<-EOF.strip
545
- ---------------
546
- name values
547
- ---------------
548
- a 1 2 3
549
- b 4 5 6
550
- c 7 8 9
551
- ---------------
552
- EOF
553
- end
554
-
555
- it "should render a table without cell borders" do
556
- @table.style = {:border_x => "", :border_y => "", :border_i => ""}
557
-
558
- @table.headings = ['name', { :value => 'values', :alignment => :right, :colspan => 3}]
559
- @table.headings = ['name', { :value => 'values', :colspan => 3}]
560
- @table.rows = [['a', 1, 2, 3], ['b', 4, 5, 6], ['c', 7, 8, 9]]
561
-
562
- @table.render.should == <<-EOF
563
-
564
- name values
565
-
566
- a 1 2 3
567
- b 4 5 6
568
- c 7 8 9
569
- EOF
570
- end
571
- end
572
- end
@@ -1,13 +0,0 @@
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
- end
@@ -1,3 +0,0 @@
1
-
2
- desc 'Build gemspec file'
3
- task :gemspec => [:build_gemspec]
@@ -1,25 +0,0 @@
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
- end