console_table 0.0.5 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -10
- data/console_table.gemspec +1 -1
- data/lib/console_table.rb +27 -4
- data/test/test_console_table.rb +145 -57
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2714908facb82595d5192b796aa3dee67b79c63e
|
4
|
+
data.tar.gz: 710aebb51608070c1ea67a72d66e3d5796f1ef9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b713ffa5e0c3073417e5fbd7b56f282cde5fa307e802bf771ca3312fc1e90e7f97e75b7903536e5fb42f2302983035a16dc1834d6231541e65c2e56ce4113050
|
7
|
+
data.tar.gz: ef98aaa437d86e63f4ee6ca91296738dba6c15a2e4e0dda5162abe72f7a88c5761363e2f5b4609d038fe6a32caddc58599337b36c448f3bc6465ef43e8dbdd3d
|
data/README.md
CHANGED
@@ -7,10 +7,12 @@ truncated or padded as needed to fit your specifications.
|
|
7
7
|
|
8
8
|
It can be used to generate output similar to this screenshot:
|
9
9
|
|
10
|
-
![image](console_table_screenshot.png
|
10
|
+
![image](console_table_screenshot.png)
|
11
11
|
|
12
12
|
You're able to specify left/right/center text justification, headers, footers, colors, and most importantly different sizes including exact character widths, screen percentages, and `*` for whatever is left. If the window resizes the class will notice and output all new lines with recalculated locations (previous lines are not re-printed).
|
13
13
|
|
14
|
+
**Note**: This project is _not_ like `hirb` and it makes no attempt to take any sort of ActiveRecord objects or an array of data and automatically fit the data to a nice table. It gives much, much more control over to the developer in how the output is formatted, but is much more difficult to work with as a trade-off - you will have to go through each element of your data set and manually munge it into the format needed by ConsoleTable to print a line. ConsoleTable is meant to save on a lot of math and calculation, but will do no analyzing of your data itself in order to format it, please consult the Usage section for more details.
|
15
|
+
|
14
16
|
|
15
17
|
## Installation
|
16
18
|
|
@@ -145,9 +147,6 @@ You can also add a title and a footer to the table, or indent the entire table w
|
|
145
147
|
|
146
148
|
```ruby
|
147
149
|
require 'console_table'
|
148
|
-
require 'terminfo'
|
149
|
-
|
150
|
-
puts TermInfo.screen_columns
|
151
150
|
|
152
151
|
table_config = [
|
153
152
|
{:key=>:title, :size=>15, :title=>"Movie Title"},
|
@@ -159,7 +158,7 @@ table_config = [
|
|
159
158
|
ConsoleTable.define(table_config, :left_margin=>5, :right_margin=>10, :title=>"Movie Killers") do |table|
|
160
159
|
table.print({
|
161
160
|
:title=>{:text=>"Friday the 13th", :highlight=>{:regex=>/[A-Z]/, :color=>:red}},
|
162
|
-
:name=>{:text=>"Jason", :justify=>:left},
|
161
|
+
:name=>{:text=>"Jason's Mom", :justify=>:left},
|
163
162
|
:release_date=>{text: "05-09-80", :color=>:blue},
|
164
163
|
:tagline=>{:text=>"They were warned...They are doomed...And on Friday the 13th, nothing will save them.", :ellipsize=>true}
|
165
164
|
})
|
@@ -171,8 +170,17 @@ ConsoleTable.define(table_config, :left_margin=>5, :right_margin=>10, :title=>"M
|
|
171
170
|
:tagline=>{:text=>"Everyone is entitled to one good scare", :ellipsize=>true}
|
172
171
|
})
|
173
172
|
|
173
|
+
table << {
|
174
|
+
:title=>{:text=>"Nightmare on Elm St.", :highlight=>{:regex=>/[A-Z]/, :color=>:red}, :background=>:orange},
|
175
|
+
:name=>{:text=>"Freddy Krueger", :justify=>:left},
|
176
|
+
:release_date=>{text: "11-16-84", :color=>:blue},
|
177
|
+
:tagline=>{:text=>"A scream that wakes you up, might be your own", :ellipsize=>true}
|
178
|
+
}
|
179
|
+
|
180
|
+
table << ["Hellraiser", "Pinhead", "9-18-87", "Demon to some. Angel to others."]
|
181
|
+
|
174
182
|
table.add_footer("This is just a line of footer text")
|
175
|
-
table.add_footer("This is a second footer with \nlots of \nlinebreaks
|
183
|
+
table.add_footer("This is a second footer with \nlots of \nlinebreaks in it.")
|
176
184
|
end
|
177
185
|
```
|
178
186
|
|
@@ -182,17 +190,19 @@ end
|
|
182
190
|
Movie Killers
|
183
191
|
Movie Title Name Release Motto
|
184
192
|
-----------------------------------------------------------------
|
185
|
-
Friday the 13th Jason
|
193
|
+
Friday the 13th Jason's Mom 05-09-80 They were warned...Th...
|
186
194
|
Halloween Michael Meyers 10-25-80 Everyone is entitled ...
|
195
|
+
Nightmare on El Freddy Krueger 11-16-84 A scream that wakes y...
|
196
|
+
Hellraiser Pinhead 9-18-87 Demon to some. Angel to
|
187
197
|
-----------------------------------------------------------------
|
188
198
|
This is just a line of footer text
|
189
199
|
This is a second footer with
|
190
200
|
lots of
|
191
|
-
|
192
|
-
|
193
|
-
=================================================================
|
201
|
+
linebreaks in it.
|
202
|
+
=================================================================
|
194
203
|
```
|
195
204
|
|
205
|
+
Note the alternative method of calling print (`<<`) and the fact that you can also supply an array instead of a hash, and ConsoleTable will infer from the array order which value goes in what column
|
196
206
|
|
197
207
|
## Contributing
|
198
208
|
|
@@ -201,3 +211,7 @@ end
|
|
201
211
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
202
212
|
4. Push to the branch (`git push origin my-new-feature`)
|
203
213
|
5. Create new Pull Request
|
214
|
+
|
215
|
+
## Warning
|
216
|
+
|
217
|
+
This gem grew out of a skunkworks project and was originally just 300 or so lines as part of a single shell script, which I moved into its own gem simply to reduce the filesize of the script. It was written and tested simply by making changes and running the script, and only when moving it to a gem did I write any tests for it at all. It is somewhat undertested and likely buggy in places that my own usage of the gem never uncovered. Please report any bugs [here](https://github.com/rodhilton/console_table/issues), but also know that I would not recommend usage of this gem for critical-path coding.
|
data/console_table.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "console_table"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.7"
|
8
8
|
spec.authors = ["Rod Hilton"]
|
9
9
|
spec.email = ["consoletable@rodhilton.com"]
|
10
10
|
spec.summary = %q{Simplifies printing tables of information to commandline consoles}
|
data/lib/console_table.rb
CHANGED
@@ -16,6 +16,7 @@ class ConsoleTable
|
|
16
16
|
@right_margin = options[:right_margin] || 0
|
17
17
|
@out = options[:output] || $stdout
|
18
18
|
@title = options[:title]
|
19
|
+
@set_width = options[:width]
|
19
20
|
|
20
21
|
@footer_lines = []
|
21
22
|
|
@@ -112,8 +113,21 @@ class ConsoleTable
|
|
112
113
|
@out.print "\n"
|
113
114
|
end
|
114
115
|
|
116
|
+
def <<(options)
|
117
|
+
print(options)
|
118
|
+
end
|
119
|
+
|
115
120
|
def print(options)
|
116
121
|
print_headings unless @headings_printed
|
122
|
+
|
123
|
+
if options.is_a? Array #If an array or something is supplied, infer the order from the heading order
|
124
|
+
munged_options = {}
|
125
|
+
options.each_with_index do |element, i|
|
126
|
+
munged_options[@original_column_layout[i][:key]] = element
|
127
|
+
end
|
128
|
+
|
129
|
+
options = munged_options
|
130
|
+
end
|
117
131
|
|
118
132
|
@out.print " "*@left_margin
|
119
133
|
#column order is set, so go through each column and look up values in the incoming options
|
@@ -133,11 +147,19 @@ class ConsoleTable
|
|
133
147
|
|
134
148
|
formatted=format(column[:size], text, ellipsize, justify)
|
135
149
|
|
136
|
-
if color != :default
|
137
|
-
formatted = formatted.colorize(
|
150
|
+
if color != :default
|
151
|
+
formatted = formatted.colorize(color)
|
138
152
|
end
|
139
153
|
|
140
|
-
|
154
|
+
if background != :default
|
155
|
+
formatted = formatted.colorize(:background=>background)
|
156
|
+
end
|
157
|
+
|
158
|
+
if mode != :default
|
159
|
+
formatted = formatted.colorize(:mode=>mode)
|
160
|
+
end
|
161
|
+
|
162
|
+
unless highlight.nil?
|
141
163
|
highlight_regex = to_print[:highlight][:regex] || /wontbefoundbecauseit'sgobbledygookblahblahblahbah/
|
142
164
|
highlight_color = to_print[:highlight][:color] || :blue
|
143
165
|
highlight_background = to_print[:highlight][:background] || :default
|
@@ -169,11 +191,12 @@ class ConsoleTable
|
|
169
191
|
def calc_column_widths()
|
170
192
|
@column_widths = []
|
171
193
|
|
194
|
+
total_width = @set_width
|
172
195
|
begin
|
173
196
|
total_width = TermInfo.screen_columns
|
174
197
|
rescue => ex
|
175
198
|
total_width = ENV["COLUMNS"].to_i || 79
|
176
|
-
end
|
199
|
+
end if total_width.nil?
|
177
200
|
|
178
201
|
keys = @original_column_layout.reject{|d| d[:key].nil?}.collect { |d| d[:key] }.uniq
|
179
202
|
if keys.length < @original_column_layout.length
|
data/test/test_console_table.rb
CHANGED
@@ -5,7 +5,6 @@ class ConsoleTableTest < Minitest::Test
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@mock_out = StringIO.new
|
8
|
-
|
9
8
|
end
|
10
9
|
|
11
10
|
def teardown
|
@@ -13,14 +12,12 @@ class ConsoleTableTest < Minitest::Test
|
|
13
12
|
end
|
14
13
|
|
15
14
|
def test_basic
|
16
|
-
|
17
|
-
|
18
|
-
commit_table_config = [
|
15
|
+
table_config = [
|
19
16
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
20
17
|
{:key=>:col2, :size=>20, :title=>"Column 2"},
|
21
18
|
]
|
22
19
|
|
23
|
-
ConsoleTable.define(
|
20
|
+
ConsoleTable.define(table_config, :width=> 100, :output=>@mock_out) do |table|
|
24
21
|
table.print({
|
25
22
|
:col1 => "Row 1, Column 1",
|
26
23
|
:col2 => "Row 1, Column 2"
|
@@ -45,15 +42,73 @@ Row 2, Column 1 Row 2, Column 1
|
|
45
42
|
assert_output_equal expected, @mock_out.string
|
46
43
|
end
|
47
44
|
|
48
|
-
def
|
49
|
-
|
45
|
+
def test_can_use_convenient_operator
|
46
|
+
table_config = [
|
47
|
+
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
48
|
+
{:key=>:col2, :size=>20, :title=>"Column 2"},
|
49
|
+
]
|
50
|
+
|
51
|
+
ConsoleTable.define(table_config, :width=>100, :output=>@mock_out) do |table|
|
52
|
+
table << {
|
53
|
+
:col1 => "Row 1, Column 1",
|
54
|
+
:col2 => "Row 1, Column 2"
|
55
|
+
}
|
50
56
|
|
51
|
-
|
57
|
+
table << {
|
58
|
+
:col1 => "Row 2, Column 1",
|
59
|
+
:col2 => "Row 2, Column 1"
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
expected=<<-END
|
64
|
+
=========================================
|
65
|
+
Column 1 Column 2
|
66
|
+
-----------------------------------------
|
67
|
+
Row 1, Column 1 Row 1, Column 2
|
68
|
+
Row 2, Column 1 Row 2, Column 1
|
69
|
+
=========================================
|
70
|
+
END
|
71
|
+
|
72
|
+
assert_output_equal expected, @mock_out.string
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_can_supply_array_and_order_is_inferred
|
76
|
+
table_config = [
|
77
|
+
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
78
|
+
{:key=>:col2, :size=>20, :title=>"Column 2"},
|
79
|
+
]
|
80
|
+
|
81
|
+
ConsoleTable.define(table_config, :width=> 100, :output=>@mock_out) do |table|
|
82
|
+
table << [
|
83
|
+
"Row 1, Column 1",
|
84
|
+
"Row 1, Column 2"
|
85
|
+
]
|
86
|
+
|
87
|
+
table << [
|
88
|
+
{:text=>"Row 2, Column 1", :justify=>:center},
|
89
|
+
{:text=>"Row 2, Column 2", :justify=>:right}
|
90
|
+
]
|
91
|
+
end
|
92
|
+
|
93
|
+
expected=<<-END
|
94
|
+
=========================================
|
95
|
+
Column 1 Column 2
|
96
|
+
-----------------------------------------
|
97
|
+
Row 1, Column 1 Row 1, Column 2
|
98
|
+
Row 2, Column 1 Row 2, Column 2
|
99
|
+
=========================================
|
100
|
+
END
|
101
|
+
|
102
|
+
assert_output_equal expected, @mock_out.string
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_percents
|
106
|
+
table_config = [
|
52
107
|
{:key=>:col1, :size=>0.3, :title=>"Column 1"},
|
53
108
|
{:key=>:col2, :size=>0.7, :title=>"Column 2"},
|
54
109
|
]
|
55
110
|
|
56
|
-
ConsoleTable.define(
|
111
|
+
ConsoleTable.define(table_config, :width=> 100, :output=>@mock_out) do |table|
|
57
112
|
table.print({
|
58
113
|
:col1 => "Row 1, Column 1",
|
59
114
|
:col2 => "Row 1, Column 2"
|
@@ -78,14 +133,12 @@ Row 2, Column 1 Row 2, Column 1
|
|
78
133
|
end
|
79
134
|
|
80
135
|
def test_star_fills_all_extra_space
|
81
|
-
|
82
|
-
|
83
|
-
commit_table_config = [
|
136
|
+
table_config = [
|
84
137
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
85
138
|
{:key=>:col2, :size=>"*", :title=>"Column 2"},
|
86
139
|
]
|
87
140
|
|
88
|
-
ConsoleTable.define(
|
141
|
+
ConsoleTable.define(table_config, :width=> 100, :output=>@mock_out) do |table|
|
89
142
|
table.print({
|
90
143
|
:col1 => "Row 1, Column 1",
|
91
144
|
:col2 => "Row 1, Column 2"
|
@@ -110,15 +163,13 @@ Row 2, Column 1 Row 2, Column 1
|
|
110
163
|
end
|
111
164
|
|
112
165
|
def test_multiple_stars_split_evenly
|
113
|
-
|
114
|
-
|
115
|
-
commit_table_config = [
|
166
|
+
table_config = [
|
116
167
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
117
168
|
{:key=>:col2, :size=>"*", :title=>"Column 2"},
|
118
169
|
{:key=>:col3, :size=>"*", :title=>"Column 3"},
|
119
170
|
]
|
120
171
|
|
121
|
-
ConsoleTable.define(
|
172
|
+
ConsoleTable.define(table_config, :width=> 100, :output=>@mock_out) do |table|
|
122
173
|
table.print({
|
123
174
|
:col1 => "Row 1, Column 1",
|
124
175
|
:col2 => "Row 1, Column 2",
|
@@ -145,14 +196,12 @@ Row 2, Column 1 Row 2, Column 1 Row 2, Column 3
|
|
145
196
|
end
|
146
197
|
|
147
198
|
def test_no_size_assumed_to_be_star
|
148
|
-
|
149
|
-
|
150
|
-
commit_table_config = [
|
199
|
+
table_config = [
|
151
200
|
{:key=>:col1, :title=>"Column 1"},
|
152
201
|
{:key=>:col2, :title=>"Column 2"},
|
153
202
|
]
|
154
203
|
|
155
|
-
ConsoleTable.define(
|
204
|
+
ConsoleTable.define(table_config, :width=> 40, :output=>@mock_out) do |table|
|
156
205
|
table.print({
|
157
206
|
:col1 => "Row 1, Column 1",
|
158
207
|
:col2 => "Row 1, Column 2",
|
@@ -172,14 +221,12 @@ Row 1, Column 1 Row 1, Column 2
|
|
172
221
|
end
|
173
222
|
|
174
223
|
def test_no_name_defaulted_to_capitalize_of_key_name
|
175
|
-
|
176
|
-
|
177
|
-
commit_table_config = [
|
224
|
+
table_config = [
|
178
225
|
{:key=>:col1},
|
179
226
|
{:key=>:col2},
|
180
227
|
]
|
181
228
|
|
182
|
-
ConsoleTable.define(
|
229
|
+
ConsoleTable.define(table_config, :width=> 40, :output=>@mock_out) do |table|
|
183
230
|
table.print({
|
184
231
|
:col1 => "Row 1, Column 1",
|
185
232
|
:col2 => "Row 1, Column 2",
|
@@ -199,9 +246,7 @@ Row 1, Column 1 Row 1, Column 2
|
|
199
246
|
end
|
200
247
|
|
201
248
|
def test_can_combine_percentages_fixed_and_stars
|
202
|
-
|
203
|
-
|
204
|
-
commit_table_config = [
|
249
|
+
table_config = [
|
205
250
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
206
251
|
{:key=>:col2, :size=>0.3, :title=>"Column 2"},
|
207
252
|
{:key=>:col3, :size=>4, :title=>"Column 3"},
|
@@ -211,7 +256,7 @@ Row 1, Column 1 Row 1, Column 2
|
|
211
256
|
{:key=>:col7, :size=>10, :title=>"Column 7"}
|
212
257
|
]
|
213
258
|
|
214
|
-
ConsoleTable.define(
|
259
|
+
ConsoleTable.define(table_config, :width=> 160, :output=>@mock_out) do |table|
|
215
260
|
table.print({
|
216
261
|
:col1 => "Row 1, Column 1",
|
217
262
|
:col2 => "Row 1, Column 2",
|
@@ -246,68 +291,56 @@ Row 2, Column 1 Row 2, Column 2 Row Row 2, Column 4
|
|
246
291
|
end
|
247
292
|
|
248
293
|
def test_wont_create_layout_too_large_for_screen
|
249
|
-
|
250
|
-
|
251
|
-
commit_table_config = [
|
294
|
+
table_config = [
|
252
295
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
253
296
|
{:key=>:col2, :size=>20, :title=>"Column 2"},
|
254
297
|
]
|
255
298
|
|
256
|
-
assert_raises(RuntimeError) { ConsoleTable.define(
|
299
|
+
assert_raises(RuntimeError) { ConsoleTable.define(table_config, :width=>30) }
|
257
300
|
end
|
258
301
|
|
259
302
|
def test_wont_create_layout_with_more_than_100_percent
|
260
|
-
|
261
|
-
|
262
|
-
commit_table_config = [
|
303
|
+
table_config = [
|
263
304
|
{:key=>:col1, :size=>0.8, :title=>"Column 1"},
|
264
305
|
{:key=>:col2, :size=>0.3, :title=>"Column 2"},
|
265
306
|
]
|
266
307
|
|
267
|
-
assert_raises(RuntimeError) { ConsoleTable.define(
|
308
|
+
assert_raises(RuntimeError) { ConsoleTable.define(table_config) }
|
268
309
|
end
|
269
310
|
|
270
311
|
def test_wont_create_layout_with_invalid_size
|
271
|
-
|
272
|
-
|
273
|
-
commit_table_config = [
|
312
|
+
table_config = [
|
274
313
|
{:key=>:col1, :size=>0.8, :title=>"Column 1"},
|
275
314
|
{:key=>:col2, :size=>"hello!", :title=>"Column 2"},
|
276
315
|
]
|
277
316
|
|
278
|
-
assert_raises(RuntimeError) { ConsoleTable.define(
|
317
|
+
assert_raises(RuntimeError) { ConsoleTable.define(table_config) }
|
279
318
|
end
|
280
319
|
|
281
320
|
def test_wont_allow_repeats_of_key_names
|
282
|
-
|
283
|
-
|
284
|
-
commit_table_config = [
|
321
|
+
table_config = [
|
285
322
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
286
323
|
{:key=>:col1, :size=>20, :title=>"Column 2"},
|
287
324
|
]
|
288
325
|
|
289
|
-
assert_raises(RuntimeError) { ConsoleTable.define(
|
326
|
+
assert_raises(RuntimeError) { ConsoleTable.define(table_config) }
|
290
327
|
end
|
291
328
|
|
292
329
|
def test_wont_allow_columns_with_no_key_name
|
293
|
-
|
294
|
-
|
295
|
-
commit_table_config = [
|
330
|
+
table_config = [
|
296
331
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
297
332
|
{:size=>20, :title=>"Column 2"},
|
298
333
|
]
|
299
334
|
|
300
|
-
assert_raises(RuntimeError) { ConsoleTable.define(
|
335
|
+
assert_raises(RuntimeError) { ConsoleTable.define(table_config) }
|
301
336
|
end
|
302
337
|
|
303
338
|
def test_can_truncate_output
|
304
|
-
|
305
|
-
|
306
|
-
commit_table_config = [
|
339
|
+
table_config = [
|
307
340
|
{:key=>:col1, :size=>20, :title=>"Column 1"}
|
308
341
|
]
|
309
342
|
|
310
|
-
ConsoleTable.define(
|
343
|
+
ConsoleTable.define(table_config, :width=> 100, :output=>@mock_out) do |table|
|
311
344
|
table.print({
|
312
345
|
:col1 => "This is short"
|
313
346
|
})
|
@@ -335,15 +368,13 @@ This is way too l...
|
|
335
368
|
end
|
336
369
|
|
337
370
|
def test_can_justify_columns_and_override_in_rows
|
338
|
-
|
339
|
-
|
340
|
-
commit_table_config = [
|
371
|
+
table_config = [
|
341
372
|
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
342
373
|
{:key=>:col2, :size=>20, :title=>"Column 2", :justify=>:center},
|
343
374
|
{:key=>:col3, :size=>20, :title=>"Column 3", :justify=>:right}
|
344
375
|
]
|
345
376
|
|
346
|
-
ConsoleTable.define(
|
377
|
+
ConsoleTable.define(table_config, :width=> 100, :output=>@mock_out) do |table|
|
347
378
|
table.print({
|
348
379
|
:col1 => "Short1",
|
349
380
|
:col2 => "Short2",
|
@@ -376,6 +407,63 @@ Short1 Short2 Short3
|
|
376
407
|
assert_output_equal expected, @mock_out.string
|
377
408
|
end
|
378
409
|
|
410
|
+
def test_huge_example
|
411
|
+
|
412
|
+
table_config = [
|
413
|
+
{:key=>:title, :size=>15, :title=>"Movie Title"},
|
414
|
+
{:key=>:name, :size=>15, :title=>"Name"},
|
415
|
+
{:key=>:release_date, :size=>8, :title=>"Release Date Too Long"},
|
416
|
+
{:key=>:tagline, :size=>"*", :title=>"Motto", :justify=>:right},
|
417
|
+
]
|
418
|
+
|
419
|
+
ConsoleTable.define(table_config, :left_margin=>5, :right_margin=>10, :width=>80, :title=>"Movie Killers", :output=>@mock_out) do |table|
|
420
|
+
table.print({
|
421
|
+
:title=>{:text=>"Friday the 13th"},
|
422
|
+
:name=>{:text=>"Jason's Mom", :justify=>:left},
|
423
|
+
:release_date=>{text: "05-09-80"},
|
424
|
+
:tagline=>{:text=>"They were warned...They are doomed...And on Friday the 13th, nothing will save them.", :ellipsize=>true}
|
425
|
+
})
|
426
|
+
|
427
|
+
table.print({
|
428
|
+
:title=>{:text=>"Halloween"},
|
429
|
+
:name=>{:text=>"Michael Meyers", :justify=>:left},
|
430
|
+
:release_date=>{text: "10-25-80"},
|
431
|
+
:tagline=>{:text=>"Everyone is entitled to one good scare", :ellipsize=>true}
|
432
|
+
})
|
433
|
+
|
434
|
+
table << {
|
435
|
+
:title=>{:text=>"Nightmare on Elm St."},
|
436
|
+
:name=>{:text=>"Freddy Krueger", :justify=>:left},
|
437
|
+
:release_date=>{text: "11-16-84"},
|
438
|
+
:tagline=>{:text=>"A scream that wakes you up, might be your own", :ellipsize=>true}
|
439
|
+
}
|
440
|
+
|
441
|
+
table << ["Hellraiser", "Pinhead", "9-18-87", "Demon to some. Angel to others."]
|
442
|
+
|
443
|
+
table.add_footer("This is just a line of footer text")
|
444
|
+
table.add_footer("This is a second footer with \nlots of \nlinebreaks in it.")
|
445
|
+
end
|
446
|
+
|
447
|
+
expected=<<-END
|
448
|
+
=================================================================
|
449
|
+
Movie Killers
|
450
|
+
Movie Title Name Release Motto
|
451
|
+
-----------------------------------------------------------------
|
452
|
+
Friday the 13th Jason's Mom 05-09-80 They were warned...Th...
|
453
|
+
Halloween Michael Meyers 10-25-80 Everyone is entitled ...
|
454
|
+
Nightmare on El Freddy Krueger 11-16-84 A scream that wakes y...
|
455
|
+
Hellraiser Pinhead 9-18-87 Demon to some. Angel to
|
456
|
+
-----------------------------------------------------------------
|
457
|
+
This is just a line of footer text
|
458
|
+
This is a second footer with
|
459
|
+
lots of
|
460
|
+
linebreaks in it.
|
461
|
+
=================================================================
|
462
|
+
END
|
463
|
+
|
464
|
+
assert_output_equal expected, @mock_out.string
|
465
|
+
end
|
466
|
+
|
379
467
|
private
|
380
468
|
def assert_output_equal(expected, actual)
|
381
469
|
expected_lines = expected.split("\n")
|