text-table 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -21,4 +21,4 @@ coverage
21
21
  rdoc
22
22
  pkg
23
23
 
24
- ## PROJECT::SPECIFIC
24
+ ## PROJECT::SPECIFIC
data/README.rdoc CHANGED
@@ -104,7 +104,10 @@ Or by passing a block:
104
104
  == Aligning Cells and Spanning Columns
105
105
 
106
106
  Alignment and column span can be specified by passing a cell as a Hash object.
107
- The acceptable aligments are <tt>:left</tt> (default), <tt>:center</tt> and <tt>:right</tt>.
107
+
108
+ The acceptable aligments are <tt>:left</tt>, <tt>:center</tt> and <tt>:right</tt>.
109
+
110
+ Cells and footers are aligned to the left by default, while headers are centered by default.
108
111
 
109
112
  table = Text::Table.new do |t|
110
113
  t.head = ['Heading A', 'Heading B']
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -54,7 +54,10 @@ module Text #:nodoc:
54
54
  # ==== Aligning Cells and Spanning Columns
55
55
  #
56
56
  # Alignment and column span can be specified by passing a cell as a Hash object.
57
- # The acceptable aligments are <tt>:left</tt> (default), <tt>:center</tt> and <tt>:right</tt>.
57
+ #
58
+ # The acceptable aligments are <tt>:left</tt>, <tt>:center</tt> and <tt>:right</tt>.
59
+ #
60
+ # Cells and footers are aligned to the left by default, while headers are centered by default.
58
61
  #
59
62
  # table = Text::Table.new do |t|
60
63
  # t.head = ['Heading A', 'Heading B']
@@ -131,7 +134,11 @@ module Text #:nodoc:
131
134
  end
132
135
 
133
136
  def text_table_head #:nodoc:
134
- Row.new(head, self) if head
137
+ defaults = {:align => :center}
138
+ Row.new(
139
+ head.map {|h| defaults.merge(h.is_a?(Hash) ? h : {:value => h})},
140
+ self
141
+ ) if head
135
142
  end
136
143
 
137
144
  def text_table_foot #:nodoc:
@@ -38,7 +38,7 @@ describe Enumerable do
38
38
  it "to Text::Table, setting first row as head" do
39
39
  @arr.to_text_table(:first_row_is_head => true).to_s.should == <<-EOS.deindent
40
40
  +----+-----+------+
41
- | 11 | 2 | 3333 |
41
+ | 11 | 2 | 3333 |
42
42
  +----+-----+------+
43
43
  | 44 | 56 | 6 |
44
44
  | 7 | 888 | 99 |
data/spec/spec.opts CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ -f s
data/spec/table_spec.rb CHANGED
@@ -1,349 +1,459 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Text::Table do
4
+
4
5
  before(:each) do
6
+ @head = %w( a bb ccc dddd )
5
7
  @rows = [
6
- [11, 2, 3333],
7
- [44, 56, 6],
8
- [7, 888, 99],
8
+ %w( aa bbb cccc d ),
9
+ %w( aaa bbbb c dd ),
9
10
  ]
10
- @head = %w( a b c )
11
- @foot = %w( x y z )
12
- @table = Text::Table.new :rows => @rows, :head => @head
11
+ @foot = %w( aaaa b cc ddd )
12
+ @table = Text::Table.new :rows => @rows, :head => @head, :foot => @foot
13
13
  end
14
14
 
15
- it "should accept rows" do
16
- @table = Text::Table.new :rows => @rows
17
- @table.rows.should == @rows
18
- end
15
+ describe 'should allow setting of attributes' do
19
16
 
20
- it 'should allow setting of rows inside a block' do
21
- @table = Text::Table.new do |t|
22
- t.rows = @rows
17
+ it 'passed as an options hash' do
18
+ @table = Text::Table.new :rows => @rows
19
+ @table.rows.should == @rows
20
+ @table = Text::Table.new :rows => @rows, :horizontal_padding => 2
21
+ @table.rows.should == @rows
22
+ @table.horizontal_padding.should == 2
23
23
  end
24
- @table.rows.should == @rows
25
- end
26
24
 
27
- it 'should accept rows with options' do
28
- @table = Text::Table.new :rows => @rows, :horizontal_padding => 2
29
- @table.rows.should == @rows
30
- @table.horizontal_padding.should == 2
31
- end
25
+ it 'inside a block' do
26
+ @table = Text::Table.new do |t|
27
+ t.rows = @rows
28
+ end
29
+ @table.rows.should == @rows
32
30
 
33
- it 'should allow setting of options inside a block' do
34
- @table = Text::Table.new do |t|
35
- t.horizontal_padding = 2
31
+ @table = Text::Table.new do |t|
32
+ t.horizontal_padding = 2
33
+ end
34
+ @table.horizontal_padding.should == 2
36
35
  end
37
- @table.horizontal_padding.should == 2
38
- end
39
-
40
- it 'should determine the proper column widths' do
41
- @table.column_widths.should == [2, 3, 4]
42
- end
43
-
44
- it 'should render tables with no headings properly' do
45
- @table = Text::Table.new :rows => @rows
46
- @table.to_s.should == <<-EOS.deindent
47
- +----+-----+------+
48
- | 11 | 2 | 3333 |
49
- | 44 | 56 | 6 |
50
- | 7 | 888 | 99 |
51
- +----+-----+------+
52
- EOS
53
- end
54
-
55
- it 'should render tables with headings properly' do
56
- @table.to_s.should == <<-EOS.deindent
57
- +----+-----+------+
58
- | a | b | c |
59
- +----+-----+------+
60
- | 11 | 2 | 3333 |
61
- | 44 | 56 | 6 |
62
- | 7 | 888 | 99 |
63
- +----+-----+------+
64
- EOS
65
- end
66
-
67
- it 'should render tables with footers properly' do
68
- @table.foot = @foot
69
- @table.to_s.should == <<-EOS.deindent
70
- +----+-----+------+
71
- | a | b | c |
72
- +----+-----+------+
73
- | 11 | 2 | 3333 |
74
- | 44 | 56 | 6 |
75
- | 7 | 888 | 99 |
76
- +----+-----+------+
77
- | x | y | z |
78
- +----+-----+------+
79
- EOS
80
- end
81
-
82
- it 'should render tables with centered headings properly' do
83
- @table = Text::Table.new :rows => @rows, :head => [
84
- {:value => 'a', :align => :center},
85
- {:value => 'b', :align => :center},
86
- {:value => 'c', :align => :center},
87
- ]
88
- @table.to_s.should == <<-EOS.deindent
89
- +----+-----+------+
90
- | a | b | c |
91
- +----+-----+------+
92
- | 11 | 2 | 3333 |
93
- | 44 | 56 | 6 |
94
- | 7 | 888 | 99 |
95
- +----+-----+------+
96
- EOS
97
- end
98
-
99
- it 'should render tables with right-justified headings properly' do
100
- @table = Text::Table.new :rows => @rows, :head => [
101
- {:value => 'a', :align => :right},
102
- {:value => 'b', :align => :right},
103
- {:value => 'c', :align => :right},
104
- ]
105
- @table.to_s.should == <<-EOS.deindent
106
- +----+-----+------+
107
- | a | b | c |
108
- +----+-----+------+
109
- | 11 | 2 | 3333 |
110
- | 44 | 56 | 6 |
111
- | 7 | 888 | 99 |
112
- +----+-----+------+
113
- EOS
114
- end
115
-
116
- it 'should render tables with centered cells properly' do
117
- @table = Text::Table.new :head => @head, :rows => @rows.map{|row| row.map{|cell| {:value => cell, :align => :center}}}
118
- @table.to_s.should == <<-EOS.deindent
119
- +----+-----+------+
120
- | a | b | c |
121
- +----+-----+------+
122
- | 11 | 2 | 3333 |
123
- | 44 | 56 | 6 |
124
- | 7 | 888 | 99 |
125
- +----+-----+------+
126
- EOS
127
- end
128
-
129
- it 'should render tables with right-justified cells properly' do
130
- @table = Text::Table.new :head => @head, :rows => @rows.map{|row| row.map{|cell| {:value => cell, :align => :right}}}
131
- @table.to_s.should == <<-EOS.deindent
132
- +----+-----+------+
133
- | a | b | c |
134
- +----+-----+------+
135
- | 11 | 2 | 3333 |
136
- | 44 | 56 | 6 |
137
- | 7 | 888 | 99 |
138
- +----+-----+------+
139
- EOS
140
- end
141
-
142
- it 'should render rows with cells spanning 2 columns' do
143
- @table = Text::Table.new :rows => @rows
144
- @table.rows << [1, {:value => 2, :colspan => 2}]
145
- @table.to_s.should == <<-EOS.deindent
146
- +----+-----+------+
147
- | 11 | 2 | 3333 |
148
- | 44 | 56 | 6 |
149
- | 7 | 888 | 99 |
150
- | 1 | 2 |
151
- +----+-----+------+
152
- EOS
153
- end
154
-
155
- it 'should render rows with 1st cell spanning 2 columns' do
156
- @table = Text::Table.new :rows => @rows
157
- @table.rows << [{:value => 333, :colspan => 2}, 1]
158
- @table.to_s.should == <<-EOS.deindent
159
- +----+-----+------+
160
- | 11 | 2 | 3333 |
161
- | 44 | 56 | 6 |
162
- | 7 | 888 | 99 |
163
- | 333 | 1 |
164
- +----+-----+------+
165
- EOS
166
- end
167
36
 
168
- it 'should render rows with cells spanning 3 columns' do
169
- @table = Text::Table.new :rows => @rows
170
- @table.rows << [{:value => 333, :colspan => 3}]
171
- @table.to_s.should == <<-EOS.deindent
172
- +----+-----+------+
173
- | 11 | 2 | 3333 |
174
- | 44 | 56 | 6 |
175
- | 7 | 888 | 99 |
176
- | 333 |
177
- +----+-----+------+
178
- EOS
179
37
  end
180
38
 
181
- it 'should render rows with centered cells spanning 2 columns' do
182
- @table = Text::Table.new :rows => @rows
183
- @table.rows << [1, {:value => 2, :colspan => 2, :align => :center}]
184
- @table.to_s.should == <<-EOS.deindent
185
- +----+-----+------+
186
- | 11 | 2 | 3333 |
187
- | 44 | 56 | 6 |
188
- | 7 | 888 | 99 |
189
- | 1 | 2 |
190
- +----+-----+------+
191
- EOS
192
- end
39
+ describe 'should properly render' do
193
40
 
194
- it 'should render rows with 1st cell spanning 2 columns' do
195
- @table = Text::Table.new :rows => @rows
196
- @table.rows << [{:value => 333, :colspan => 2, :align => :center}, 1]
197
- @table.to_s.should == <<-EOS.deindent
198
- +----+-----+------+
199
- | 11 | 2 | 3333 |
200
- | 44 | 56 | 6 |
201
- | 7 | 888 | 99 |
202
- | 333 | 1 |
203
- +----+-----+------+
204
- EOS
205
- end
41
+ it 'column widths' do
42
+ @table.column_widths.should == [4, 4, 4, 4]
43
+ end
206
44
 
207
- it 'should render rows with centered cells spanning 3 columns' do
208
- @table = Text::Table.new :rows => @rows
209
- @table.rows << [{:value => 333, :colspan => 3, :align => :center}]
210
- @table.to_s.should == <<-EOS.deindent
211
- +----+-----+------+
212
- | 11 | 2 | 3333 |
213
- | 44 | 56 | 6 |
214
- | 7 | 888 | 99 |
215
- | 333 |
216
- +----+-----+------+
217
- EOS
218
- end
45
+ it 'rows' do
46
+ @table = Text::Table.new :rows => @rows
47
+ @table.to_s.should == <<-EOS.deindent
48
+ +-----+------+------+----+
49
+ | aa | bbb | cccc | d |
50
+ | aaa | bbbb | c | dd |
51
+ +-----+------+------+----+
52
+ EOS
53
+ end
219
54
 
220
- it 'should render rows with right-justified cells spanning 2 columns' do
221
- @table = Text::Table.new :rows => @rows
222
- @table.rows << [1, {:value => 2, :colspan => 2, :align => :right}]
223
- @table.to_s.should == <<-EOS.deindent
224
- +----+-----+------+
225
- | 11 | 2 | 3333 |
226
- | 44 | 56 | 6 |
227
- | 7 | 888 | 99 |
228
- | 1 | 2 |
229
- +----+-----+------+
230
- EOS
231
- end
55
+ it 'headers' do
56
+ @table = Text::Table.new :rows => @rows, :head => @head
57
+ @table.to_s.should == <<-EOS.deindent
58
+ +-----+------+------+------+
59
+ | a | bb | ccc | dddd |
60
+ +-----+------+------+------+
61
+ | aa | bbb | cccc | d |
62
+ | aaa | bbbb | c | dd |
63
+ +-----+------+------+------+
64
+ EOS
65
+ end
232
66
 
233
- it 'should render rows with 1st cell spanning 2 columns' do
234
- @table = Text::Table.new :rows => @rows
235
- @table.rows << [{:value => 333, :colspan => 2, :align => :right}, 1]
236
- @table.to_s.should == <<-EOS.deindent
237
- +----+-----+------+
238
- | 11 | 2 | 3333 |
239
- | 44 | 56 | 6 |
240
- | 7 | 888 | 99 |
241
- | 333 | 1 |
242
- +----+-----+------+
243
- EOS
244
- end
67
+ it 'footers' do
68
+ @table = Text::Table.new :rows => @rows, :foot => @foot
69
+ @table.to_s.should == <<-EOS.deindent
70
+ +------+------+------+-----+
71
+ | aa | bbb | cccc | d |
72
+ | aaa | bbbb | c | dd |
73
+ +------+------+------+-----+
74
+ | aaaa | b | cc | ddd |
75
+ +------+------+------+-----+
76
+ EOS
77
+ end
245
78
 
246
- it 'should render rows with right-justified cells spanning 3 columns' do
247
- @table = Text::Table.new :rows => @rows
248
- @table.rows << [{:value => 333, :colspan => 3, :align => :right}]
249
- @table.to_s.should == <<-EOS.deindent
250
- +----+-----+------+
251
- | 11 | 2 | 3333 |
252
- | 44 | 56 | 6 |
253
- | 7 | 888 | 99 |
254
- | 333 |
255
- +----+-----+------+
256
- EOS
257
- end
79
+ it "separators" do
80
+ @table = Text::Table.new :rows => @rows.insert(1, :separator)
81
+ @table.to_s.should == <<-EOS.deindent
82
+ +-----+------+------+----+
83
+ | aa | bbb | cccc | d |
84
+ +-----+------+------+----+
85
+ | aaa | bbbb | c | dd |
86
+ +-----+------+------+----+
87
+ EOS
88
+ end
258
89
 
259
- it "should allow adding of separators between rows" do
260
- @table = Text::Table.new :rows => @rows
261
- @table.rows << :separator
262
- @table.rows << [1, 2, 3]
263
- @table.rows << :separator
264
- @table.rows << [{:value => 5, :colspan => 3, :align => :right}]
265
- @table.to_s.should == <<-EOS.deindent
266
- +----+-----+------+
267
- | 11 | 2 | 3333 |
268
- | 44 | 56 | 6 |
269
- | 7 | 888 | 99 |
270
- +----+-----+------+
271
- | 1 | 2 | 3 |
272
- +----+-----+------+
273
- | 5 |
274
- +----+-----+------+
275
- EOS
276
- end
90
+ it 'horizontal boundaries' do
91
+ @table.horizontal_boundary = ':'
92
+ @table.to_s.should == <<-EOS.deindent
93
+ +------+------+------+------+
94
+ : a : bb : ccc : dddd :
95
+ +------+------+------+------+
96
+ : aa : bbb : cccc : d :
97
+ : aaa : bbbb : c : dd :
98
+ +------+------+------+------+
99
+ : aaaa : b : cc : ddd :
100
+ +------+------+------+------+
101
+ EOS
102
+ end
277
103
 
278
- it 'should render horizontal boundaries correctly' do
279
- @table.horizontal_boundary = ':'
280
- @table.to_s.should == <<-EOS.deindent
281
- +----+-----+------+
282
- : a : b : c :
283
- +----+-----+------+
284
- : 11 : 2 : 3333 :
285
- : 44 : 56 : 6 :
286
- : 7 : 888 : 99 :
287
- +----+-----+------+
288
- EOS
289
- end
104
+ it 'vertical boundaries' do
105
+ @table.vertical_boundary = '='
106
+ @table.to_s.should == <<-EOS.deindent
107
+ +======+======+======+======+
108
+ | a | bb | ccc | dddd |
109
+ +======+======+======+======+
110
+ | aa | bbb | cccc | d |
111
+ | aaa | bbbb | c | dd |
112
+ +======+======+======+======+
113
+ | aaaa | b | cc | ddd |
114
+ +======+======+======+======+
115
+ EOS
116
+ end
290
117
 
291
- it 'should render vertical boundaries correctly' do
292
- @table.vertical_boundary = '='
293
- @table.to_s.should == <<-EOS.deindent
294
- +====+=====+======+
295
- | a | b | c |
296
- +====+=====+======+
297
- | 11 | 2 | 3333 |
298
- | 44 | 56 | 6 |
299
- | 7 | 888 | 99 |
300
- +====+=====+======+
301
- EOS
302
- end
118
+ it 'boundary interserctions' do
119
+ @table.boundary_intersection = '*'
120
+ @table.to_s.should == <<-EOS.deindent
121
+ *------*------*------*------*
122
+ | a | bb | ccc | dddd |
123
+ *------*------*------*------*
124
+ | aa | bbb | cccc | d |
125
+ | aaa | bbbb | c | dd |
126
+ *------*------*------*------*
127
+ | aaaa | b | cc | ddd |
128
+ *------*------*------*------*
129
+ EOS
130
+ end
303
131
 
304
- it 'should render boundary interserctions properly' do
305
- @table.boundary_intersection = '*'
306
- @table.to_s.should == <<-EOS.deindent
307
- *----*-----*------*
308
- | a | b | c |
309
- *----*-----*------*
310
- | 11 | 2 | 3333 |
311
- | 44 | 56 | 6 |
312
- | 7 | 888 | 99 |
313
- *----*-----*------*
314
- EOS
315
- end
132
+ it 'double horizontal boundaries' do
133
+ @table.horizontal_boundary = '||'
134
+ @table.boundary_intersection = '++'
135
+ @table.to_s.should == <<-EOS.deindent
136
+ ++------++------++------++------++
137
+ || a || bb || ccc || dddd ||
138
+ ++------++------++------++------++
139
+ || aa || bbb || cccc || d ||
140
+ || aaa || bbbb || c || dd ||
141
+ ++------++------++------++------++
142
+ || aaaa || b || cc || ddd ||
143
+ ++------++------++------++------++
144
+ EOS
145
+ end
316
146
 
317
- it 'should render double horizontal boundaries properly' do
318
- @table.horizontal_boundary = '||'
319
- @table.boundary_intersection = '**'
320
- @table.to_s.should == <<-EOS.deindent
321
- **----**-----**------**
322
- || a || b || c ||
323
- **----**-----**------**
324
- || 11 || 2 || 3333 ||
325
- || 44 || 56 || 6 ||
326
- || 7 || 888 || 99 ||
327
- **----**-----**------**
328
- EOS
329
- end
147
+ it 'double horizontal boundaries with spanned cells' do
148
+ @table.horizontal_boundary = '||'
149
+ @table.boundary_intersection = '++'
150
+ @table.rows << :separator
151
+ @table.rows << [{:value => 'x', :colspan => 2, :align => :right}, 'c', 'd']
152
+ @table.to_s.should == <<-EOS.deindent
153
+ ++------++------++------++------++
154
+ || a || bb || ccc || dddd ||
155
+ ++------++------++------++------++
156
+ || aa || bbb || cccc || d ||
157
+ || aaa || bbbb || c || dd ||
158
+ ++------++------++------++------++
159
+ || x || c || d ||
160
+ ++------++------++------++------++
161
+ || aaaa || b || cc || ddd ||
162
+ ++------++------++------++------++
163
+ EOS
164
+ end
330
165
 
331
- it 'should render double horizontal boundaries with spanned cells properly' do
332
- @table.horizontal_boundary = '||'
333
- @table.boundary_intersection = '**'
334
- @table.rows << :separator
335
- @table.rows << [{:value => 2, :colspan => 2, :align => :right}, 1]
336
- @table.to_s.should == <<-EOS.deindent
337
- **----**-----**------**
338
- || a || b || c ||
339
- **----**-----**------**
340
- || 11 || 2 || 3333 ||
341
- || 44 || 56 || 6 ||
342
- || 7 || 888 || 99 ||
343
- **----**-----**------**
344
- || 2 || 1 ||
345
- **----**-----**------**
346
- EOS
166
+ describe 'alignment of' do
167
+ describe 'headers to the' do
168
+ it 'left' do
169
+ @table = Text::Table.new :rows => @rows, :head => @head.map {|h| {:value => h, :align => :left}}
170
+ @table.to_s.should == <<-EOS.deindent
171
+ +-----+------+------+------+
172
+ | a | bb | ccc | dddd |
173
+ +-----+------+------+------+
174
+ | aa | bbb | cccc | d |
175
+ | aaa | bbbb | c | dd |
176
+ +-----+------+------+------+
177
+ EOS
178
+ end
179
+ it 'center (default)' do
180
+ @table = Text::Table.new :rows => @rows, :head => @head
181
+ @table.to_s.should == <<-EOS.deindent
182
+ +-----+------+------+------+
183
+ | a | bb | ccc | dddd |
184
+ +-----+------+------+------+
185
+ | aa | bbb | cccc | d |
186
+ | aaa | bbbb | c | dd |
187
+ +-----+------+------+------+
188
+ EOS
189
+ end
190
+ it 'right' do
191
+ @table = Text::Table.new :rows => @rows, :head => @head.map {|h| {:value => h, :align => :right}}
192
+ @table.to_s.should == <<-EOS.deindent
193
+ +-----+------+------+------+
194
+ | a | bb | ccc | dddd |
195
+ +-----+------+------+------+
196
+ | aa | bbb | cccc | d |
197
+ | aaa | bbbb | c | dd |
198
+ +-----+------+------+------+
199
+ EOS
200
+ end
201
+ end
202
+ describe 'cells to the' do
203
+ it 'left (default)' do
204
+ @table.to_s.should == <<-EOS.deindent
205
+ +------+------+------+------+
206
+ | a | bb | ccc | dddd |
207
+ +------+------+------+------+
208
+ | aa | bbb | cccc | d |
209
+ | aaa | bbbb | c | dd |
210
+ +------+------+------+------+
211
+ | aaaa | b | cc | ddd |
212
+ +------+------+------+------+
213
+ EOS
214
+ end
215
+ it 'center' do
216
+ @table = Text::Table.new :rows => @rows.map {|r| r.map {|c| {:value => c, :align => :center}}}, :head => @head, :foot => @foot
217
+ @table.to_s.should == <<-EOS.deindent
218
+ +------+------+------+------+
219
+ | a | bb | ccc | dddd |
220
+ +------+------+------+------+
221
+ | aa | bbb | cccc | d |
222
+ | aaa | bbbb | c | dd |
223
+ +------+------+------+------+
224
+ | aaaa | b | cc | ddd |
225
+ +------+------+------+------+
226
+ EOS
227
+ end
228
+ it 'right' do
229
+ @table = Text::Table.new :rows => @rows.map {|r| r.map {|c| {:value => c, :align => :right}}}, :head => @head, :foot => @foot
230
+ @table.to_s.should == <<-EOS.deindent
231
+ +------+------+------+------+
232
+ | a | bb | ccc | dddd |
233
+ +------+------+------+------+
234
+ | aa | bbb | cccc | d |
235
+ | aaa | bbbb | c | dd |
236
+ +------+------+------+------+
237
+ | aaaa | b | cc | ddd |
238
+ +------+------+------+------+
239
+ EOS
240
+ end
241
+ end
242
+ describe 'footers to the' do
243
+ it 'left (default)' do
244
+ @table = Text::Table.new :rows => @rows, :foot => @foot
245
+ @table.to_s.should == <<-EOS.deindent
246
+ +------+------+------+-----+
247
+ | aa | bbb | cccc | d |
248
+ | aaa | bbbb | c | dd |
249
+ +------+------+------+-----+
250
+ | aaaa | b | cc | ddd |
251
+ +------+------+------+-----+
252
+ EOS
253
+ end
254
+ it 'center' do
255
+ @table = Text::Table.new :rows => @rows, :foot => @foot.map {|f| {:value => f, :align => :center}}
256
+ @table.to_s.should == <<-EOS.deindent
257
+ +------+------+------+-----+
258
+ | aa | bbb | cccc | d |
259
+ | aaa | bbbb | c | dd |
260
+ +------+------+------+-----+
261
+ | aaaa | b | cc | ddd |
262
+ +------+------+------+-----+
263
+ EOS
264
+ end
265
+ it 'right' do
266
+ @table = Text::Table.new :rows => @rows, :foot => @foot.map {|f| {:value => f, :align => :right}}
267
+ @table.to_s.should == <<-EOS.deindent
268
+ +------+------+------+-----+
269
+ | aa | bbb | cccc | d |
270
+ | aaa | bbbb | c | dd |
271
+ +------+------+------+-----+
272
+ | aaaa | b | cc | ddd |
273
+ +------+------+------+-----+
274
+ EOS
275
+ end
276
+ end
277
+ end
278
+ describe 'last columns spanned by' do
279
+ describe '2 cells aligned to the' do
280
+ it 'left' do
281
+ @table.rows << ['a', 'b', {:value => 'x', :colspan => 2}]
282
+ @table.to_s.should == <<-EOS.deindent
283
+ +------+------+------+------+
284
+ | a | bb | ccc | dddd |
285
+ +------+------+------+------+
286
+ | aa | bbb | cccc | d |
287
+ | aaa | bbbb | c | dd |
288
+ | a | b | x |
289
+ +------+------+------+------+
290
+ | aaaa | b | cc | ddd |
291
+ +------+------+------+------+
292
+ EOS
293
+ end
294
+ it 'center' do
295
+ @table.rows << ['a', 'b', {:value => 'x', :colspan => 2, :align => :center}]
296
+ @table.to_s.should == <<-EOS.deindent
297
+ +------+------+------+------+
298
+ | a | bb | ccc | dddd |
299
+ +------+------+------+------+
300
+ | aa | bbb | cccc | d |
301
+ | aaa | bbbb | c | dd |
302
+ | a | b | x |
303
+ +------+------+------+------+
304
+ | aaaa | b | cc | ddd |
305
+ +------+------+------+------+
306
+ EOS
307
+ end
308
+ it 'right' do
309
+ @table.rows << ['a', 'b', {:value => 'x', :colspan => 2, :align => :right}]
310
+ @table.to_s.should == <<-EOS.deindent
311
+ +------+------+------+------+
312
+ | a | bb | ccc | dddd |
313
+ +------+------+------+------+
314
+ | aa | bbb | cccc | d |
315
+ | aaa | bbbb | c | dd |
316
+ | a | b | x |
317
+ +------+------+------+------+
318
+ | aaaa | b | cc | ddd |
319
+ +------+------+------+------+
320
+ EOS
321
+ end
322
+ end
323
+ describe '3 cells aligned to the' do
324
+ it 'left' do
325
+ @table.rows << ['a', {:value => 'x', :colspan => 3}]
326
+ @table.to_s.should == <<-EOS.deindent
327
+ +------+------+------+------+
328
+ | a | bb | ccc | dddd |
329
+ +------+------+------+------+
330
+ | aa | bbb | cccc | d |
331
+ | aaa | bbbb | c | dd |
332
+ | a | x |
333
+ +------+------+------+------+
334
+ | aaaa | b | cc | ddd |
335
+ +------+------+------+------+
336
+ EOS
337
+ end
338
+ it 'center' do
339
+ @table.rows << ['a', {:value => 'x', :colspan => 3, :align => :center}]
340
+ @table.to_s.should == <<-EOS.deindent
341
+ +------+------+------+------+
342
+ | a | bb | ccc | dddd |
343
+ +------+------+------+------+
344
+ | aa | bbb | cccc | d |
345
+ | aaa | bbbb | c | dd |
346
+ | a | x |
347
+ +------+------+------+------+
348
+ | aaaa | b | cc | ddd |
349
+ +------+------+------+------+
350
+ EOS
351
+ end
352
+ it 'right' do
353
+ @table.rows << ['a', {:value => 'x', :colspan => 3, :align => :right}]
354
+ @table.to_s.should == <<-EOS.deindent
355
+ +------+------+------+------+
356
+ | a | bb | ccc | dddd |
357
+ +------+------+------+------+
358
+ | aa | bbb | cccc | d |
359
+ | aaa | bbbb | c | dd |
360
+ | a | x |
361
+ +------+------+------+------+
362
+ | aaaa | b | cc | ddd |
363
+ +------+------+------+------+
364
+ EOS
365
+ end
366
+ end
367
+ end
368
+ describe 'first columns spanned by' do
369
+ describe '2 cells aligned to the' do
370
+ it 'left' do
371
+ @table.rows << [{:value => 'x', :colspan => 2}, 'c', 'd']
372
+ @table.to_s.should == <<-EOS.deindent
373
+ +------+------+------+------+
374
+ | a | bb | ccc | dddd |
375
+ +------+------+------+------+
376
+ | aa | bbb | cccc | d |
377
+ | aaa | bbbb | c | dd |
378
+ | x | c | d |
379
+ +------+------+------+------+
380
+ | aaaa | b | cc | ddd |
381
+ +------+------+------+------+
382
+ EOS
383
+ end
384
+ it 'center' do
385
+ @table.rows << [{:value => 'x', :colspan => 2, :align => :center}, 'c', 'd']
386
+ @table.to_s.should == <<-EOS.deindent
387
+ +------+------+------+------+
388
+ | a | bb | ccc | dddd |
389
+ +------+------+------+------+
390
+ | aa | bbb | cccc | d |
391
+ | aaa | bbbb | c | dd |
392
+ | x | c | d |
393
+ +------+------+------+------+
394
+ | aaaa | b | cc | ddd |
395
+ +------+------+------+------+
396
+ EOS
397
+ end
398
+ it 'right' do
399
+ @table.rows << [{:value => 'x', :colspan => 2, :align => :right}, 'c', 'd']
400
+ @table.to_s.should == <<-EOS.deindent
401
+ +------+------+------+------+
402
+ | a | bb | ccc | dddd |
403
+ +------+------+------+------+
404
+ | aa | bbb | cccc | d |
405
+ | aaa | bbbb | c | dd |
406
+ | x | c | d |
407
+ +------+------+------+------+
408
+ | aaaa | b | cc | ddd |
409
+ +------+------+------+------+
410
+ EOS
411
+ end
412
+ end
413
+ describe '3 cells aligned to the' do
414
+ it 'left' do
415
+ @table.rows << [{:value => 'x', :colspan => 3}, 'd']
416
+ @table.to_s.should == <<-EOS.deindent
417
+ +------+------+------+------+
418
+ | a | bb | ccc | dddd |
419
+ +------+------+------+------+
420
+ | aa | bbb | cccc | d |
421
+ | aaa | bbbb | c | dd |
422
+ | x | d |
423
+ +------+------+------+------+
424
+ | aaaa | b | cc | ddd |
425
+ +------+------+------+------+
426
+ EOS
427
+ end
428
+ it 'center' do
429
+ @table.rows << [{:value => 'x', :colspan => 3, :align => :center}, 'd']
430
+ @table.to_s.should == <<-EOS.deindent
431
+ +------+------+------+------+
432
+ | a | bb | ccc | dddd |
433
+ +------+------+------+------+
434
+ | aa | bbb | cccc | d |
435
+ | aaa | bbbb | c | dd |
436
+ | x | d |
437
+ +------+------+------+------+
438
+ | aaaa | b | cc | ddd |
439
+ +------+------+------+------+
440
+ EOS
441
+ end
442
+ it 'right' do
443
+ @table.rows << [{:value => 'x', :colspan => 3, :align => :right}, 'd']
444
+ @table.to_s.should == <<-EOS.deindent
445
+ +------+------+------+------+
446
+ | a | bb | ccc | dddd |
447
+ +------+------+------+------+
448
+ | aa | bbb | cccc | d |
449
+ | aaa | bbbb | c | dd |
450
+ | x | d |
451
+ +------+------+------+------+
452
+ | aaaa | b | cc | ddd |
453
+ +------+------+------+------+
454
+ EOS
455
+ end
456
+ end
457
+ end
347
458
  end
348
-
349
459
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text-table
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Tinio
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-21 00:00:00 +08:00
12
+ date: 2009-12-28 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency