visionmedia-terminal-table 1.0.1 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ === 1.0.3 / 2009-01-15
3
+
4
+ * Moved yield or eval to Terminal::Table initialize where it belongs
5
+
2
6
  === 1.0.0 / 2009-01-13
3
7
 
4
8
  * Initial release
data/README.rdoc CHANGED
@@ -31,13 +31,13 @@ Simple, feature rich ASCII table generator.
31
31
  end
32
32
  puts user_table
33
33
 
34
- user_table = table do
35
- self.headings = 'First Name', 'Last Name', 'Email'
36
- add_row ['TJ', 'Holowaychuk', { :value => 'tj@vision-media.ca', :align => :right }]
37
- add_row ['Bob', 'Someone', 'bob@vision-media.ca']
38
- add_row ['Joe', 'Whatever', 'joe@vision-media.ca']
39
- align_column 1, :center
40
- end
34
+ user_table = table do
35
+ self.headings = 'First Name', 'Last Name', 'Email'
36
+ add_row ['TJ', 'Holowaychuk', { :value => 'tj@vision-media.ca', :align => :right }]
37
+ add_row ['Bob', 'Someone', 'bob@vision-media.ca']
38
+ add_row ['Joe', 'Whatever', 'joe@vision-media.ca']
39
+ align_column 1, :center
40
+ end
41
41
  puts user_table
42
42
 
43
43
  rows = []
@@ -78,13 +78,13 @@ Simple, feature rich ASCII table generator.
78
78
  | Joe | Whatever | joe@vision-media.ca |
79
79
  +------------+-------------+---------------------+
80
80
 
81
- +------------+-----------------------------+---------------------+
82
- | First Name | Last Name | Email |
83
- +------------+-----------------------------+---------------------+
84
- | TJ | Holowaychuk | tj@vision-media.ca |
85
- | Bob | Someone | bob@vision-media.ca |
86
- | Joe | Whatever | joe@vision-media.ca |
87
- +------------+-----------------------------+---------------------+
81
+ +------------+-----------------------------+---------------------+
82
+ | First Name | Last Name | Email |
83
+ +------------+-----------------------------+---------------------+
84
+ | TJ | Holowaychuk | tj@vision-media.ca |
85
+ | Bob | Someone | bob@vision-media.ca |
86
+ | Joe | Whatever | joe@vision-media.ca |
87
+ +------------+-----------------------------+---------------------+
88
88
 
89
89
  +------------+-------+
90
90
  | | Lines |
@@ -48,8 +48,6 @@ module Kernel
48
48
  #
49
49
 
50
50
  def table headings = [], rows = [], &block
51
- table = Terminal::Table.new :headings => headings, :rows => rows
52
- table.yield_or_eval &block
53
- table
51
+ table = Terminal::Table.new :headings => headings, :rows => rows, &block
54
52
  end
55
53
  end
@@ -29,6 +29,12 @@ module Terminal
29
29
 
30
30
  class Table
31
31
 
32
+ #--
33
+ # Exceptions
34
+ #++
35
+
36
+ class Error < StandardError; end
37
+
32
38
  ##
33
39
  # Table characters, x axis, y axis, and intersection.
34
40
 
@@ -39,9 +45,10 @@ module Terminal
39
45
  ##
40
46
  # Generates a ASCII table.
41
47
 
42
- def initialize options = {}
48
+ def initialize options = {}, &block
43
49
  @headings = options.delete(:headings) || []
44
- @rows = options.delete(:rows) || []
50
+ @rows = options.delete(:rows) || []
51
+ yield_or_eval &block if block_given?
45
52
  end
46
53
 
47
54
  ##
@@ -118,8 +125,12 @@ module Terminal
118
125
  ##
119
126
  # Return total number of columns available.
120
127
 
121
- def number_of_columns
122
- rows[0].length
128
+ def number_of_columns
129
+ if rows[0]
130
+ rows[0].length
131
+ else
132
+ raise Error, 'Your table needs some rows'
133
+ end
123
134
  end
124
135
 
125
136
  ##
@@ -2,7 +2,7 @@
2
2
  module Terminal
3
3
  class Table
4
4
  module VERSION #:nodoc:
5
- MAJOR, MINOR, TINY = [1, 0, 1]
5
+ MAJOR, MINOR, TINY = [1, 0, 4]
6
6
  STRING = [MAJOR, MINOR, TINY].join '.'
7
7
  end
8
8
  end
data/spec/table_spec.rb CHANGED
@@ -89,6 +89,36 @@ describe Terminal::Table do
89
89
  EOF
90
90
  end
91
91
 
92
+ it "should render properly using block syntax" do
93
+ table = Terminal::Table.new do |t|
94
+ t << ['a', 1]
95
+ t << ['b', 2]
96
+ t << ['c', 3]
97
+ end
98
+ table.render.should == <<-EOF.deindent
99
+ +---+---+
100
+ | a | 1 |
101
+ | b | 2 |
102
+ | c | 3 |
103
+ +---+---+
104
+ EOF
105
+ end
106
+
107
+ it "should render properly using instance_eval block syntax" do
108
+ table = Terminal::Table.new do
109
+ add_row ['a', 1]
110
+ add_row ['b', 2]
111
+ add_row ['c', 3]
112
+ end
113
+ table.render.should == <<-EOF.deindent
114
+ +---+---+
115
+ | a | 1 |
116
+ | b | 2 |
117
+ | c | 3 |
118
+ +---+---+
119
+ EOF
120
+ end
121
+
92
122
  it "should allows a hash of options for creation" do
93
123
  headings = ['Char', 'Num']
94
124
  rows = [['a', 1], ['b', 2], ['c', 3]]
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{terminal-table}
5
- s.version = "1.0.1"
5
+ s.version = "1.0.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"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visionmedia-terminal-table
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk