visionmedia-terminal-table 1.0.1 → 1.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/History.rdoc +4 -0
- data/README.rdoc +14 -14
- data/lib/terminal-table/import.rb +1 -3
- data/lib/terminal-table/table.rb +15 -4
- data/lib/terminal-table/version.rb +1 -1
- data/spec/table_spec.rb +30 -0
- data/terminal-table.gemspec +1 -1
- metadata +1 -1
data/History.rdoc
CHANGED
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
data/lib/terminal-table/table.rb
CHANGED
@@ -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]
|
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
|
##
|
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]]
|
data/terminal-table.gemspec
CHANGED