console_table 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/console_table.gemspec +2 -2
- data/lib/console_table.rb +66 -68
- data/test/console_table_test.rb +238 -0
- data/todo.txt +2 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 319bf461a967b3098c88d16ed370e6b32cfe0a11
|
4
|
+
data.tar.gz: 82ac42a1dcc1680f982ddafa7a9613a28a7a0d42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c0bdfbc856c1f7e04a7b9a3adfc3d259472947293a8812637395d233f1bc14ce68bc0e1730312012c4fd87765cb66e07ace95a74c7d27ab2c0f790ce552802b
|
7
|
+
data.tar.gz: 64a60d6b7571dcabee14970cc6b9bef3768c2bbcf9663c7d03378ea26085c8b466f7e28a0e56d666b709f92a2d9c562ef844fc6be7e1bb9b33871d99a4cfd6ad
|
data/README.md
CHANGED
data/console_table.gemspec
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'console_table/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
6
|
spec.name = "console_table"
|
8
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.3"
|
9
8
|
spec.authors = ["Rod Hilton"]
|
10
9
|
spec.email = ["consoletable@rodhilton.com"]
|
11
10
|
spec.summary = %q{Simplifies printing tables of information to commandline consoles}
|
@@ -19,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
19
18
|
|
20
19
|
spec.add_development_dependency "bundler", "~> 1.5"
|
21
20
|
spec.add_development_dependency 'rake', '~> 0'
|
21
|
+
spec.add_development_dependency 'simplecov', '~> 0.9'
|
22
22
|
|
23
23
|
spec.add_runtime_dependency 'colorize', '~> 0.7'
|
24
24
|
end
|
data/lib/console_table.rb
CHANGED
@@ -1,60 +1,61 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
|
1
3
|
class ConsoleTable
|
2
|
-
|
3
|
-
def self.define(layout, options, &block)
|
4
|
+
|
5
|
+
def self.define(layout, options={}, &block)
|
4
6
|
table = ConsoleTable.new(layout, options)
|
5
|
-
table.print_header
|
7
|
+
table.print_header
|
6
8
|
block.call(table)
|
7
|
-
table.print_footer
|
9
|
+
table.print_footer
|
8
10
|
end
|
9
11
|
|
10
12
|
def initialize(column_layout, options={})
|
11
13
|
@original_column_layout = column_layout
|
12
14
|
@left_margin = options[:left_margin] || 0
|
13
15
|
@right_margin = options[:right_margin] || 0
|
14
|
-
|
15
|
-
@count = 0
|
16
|
-
|
16
|
+
@out = options[:output] || $stdout
|
17
17
|
@title = options[:title]
|
18
18
|
|
19
19
|
@footer_lines = []
|
20
20
|
|
21
|
-
calc_column_widths()
|
22
21
|
@headings_printed = false
|
22
|
+
@count = 0
|
23
23
|
|
24
|
-
|
24
|
+
calc_column_widths
|
25
|
+
Signal.trap('SIGWINCH', proc { calc_column_widths })
|
25
26
|
end
|
26
27
|
|
27
28
|
def print_header()
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
@out.print " " * @left_margin
|
30
|
+
@out.print "=" * @working_width
|
31
|
+
@out.print "\n"
|
31
32
|
|
32
33
|
if not @title.nil? and @title.length <= @working_width
|
33
|
-
|
34
|
+
@out.print " "*@left_margin
|
34
35
|
left_side = (@working_width - @title.uncolorize.length)/2
|
35
36
|
right_side = (@working_width - @title.uncolorize.length) - left_side
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
@out.print " "*left_side
|
38
|
+
@out.print @title
|
39
|
+
@out.print " "*right_side
|
40
|
+
@out.print "\n"
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
43
44
|
def print_headings()
|
44
45
|
@headings_printed = true
|
45
|
-
|
46
|
+
@out.print " "*@left_margin
|
46
47
|
|
47
48
|
@column_widths.each_with_index do |column, i|
|
48
49
|
justify = column[:justify] || :left
|
49
50
|
title = column[:title].strip
|
50
|
-
|
51
|
-
|
51
|
+
@out.print format(column[:size], title, false, justify)
|
52
|
+
@out.print " " if i < @column_widths.size-1
|
52
53
|
end
|
53
|
-
|
54
|
+
@out.print "\n"
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
@out.print " " * @left_margin
|
57
|
+
@out.print "-" * @working_width
|
58
|
+
@out.print "\n"
|
58
59
|
end
|
59
60
|
|
60
61
|
def add_footer(line)
|
@@ -65,33 +66,33 @@ class ConsoleTable
|
|
65
66
|
end
|
66
67
|
|
67
68
|
def print_footer()
|
68
|
-
should_print_footer = @footer_lines.length > 0 && @footer_lines.any?{|l| l.uncolorize.length <= @working_width}
|
69
|
+
should_print_footer = @footer_lines.length > 0 && @footer_lines.any? { |l| l.uncolorize.length <= @working_width }
|
69
70
|
|
70
|
-
if
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
if should_print_footer
|
72
|
+
@out.print " " * @left_margin
|
73
|
+
@out.print "-" * @working_width
|
74
|
+
@out.print "\n"
|
74
75
|
end
|
75
76
|
|
76
77
|
@footer_lines.each do |line|
|
77
78
|
if line.uncolorize.length <= @working_width
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
@out.print " " * @left_margin
|
80
|
+
@out.print " " * (@working_width - line.uncolorize.length)
|
81
|
+
@out.print line
|
82
|
+
@out.print "\n"
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
@out.print " " * @left_margin
|
87
|
+
@out.print "=" * @working_width
|
88
|
+
@out.print "\n"
|
88
89
|
end
|
89
90
|
|
90
91
|
def print_plain(to_print)
|
91
|
-
|
92
|
+
@out.print " "*@left_margin
|
92
93
|
|
93
94
|
if to_print.is_a? String
|
94
|
-
|
95
|
+
@out.print format(@working_width, normalize(to_print))
|
95
96
|
elsif to_print.is_a? Hash
|
96
97
|
color = to_print[:color] || :default
|
97
98
|
background = to_print[:background] || :default
|
@@ -100,23 +101,23 @@ class ConsoleTable
|
|
100
101
|
justify = to_print[:justify] || :left
|
101
102
|
mode = to_print[:mode] || :default
|
102
103
|
|
103
|
-
formatted=format(@working_width, text, ellipsize, justify).colorize(:color=>color, :background=>background, :mode=>mode)
|
104
|
-
|
104
|
+
formatted=format(@working_width, text, ellipsize, justify).colorize(:color => color, :background => background, :mode => mode)
|
105
|
+
@out.print formatted
|
105
106
|
end
|
106
107
|
|
107
|
-
|
108
|
+
@out.print "\n"
|
108
109
|
end
|
109
110
|
|
110
111
|
def print(options)
|
111
112
|
print_headings unless @headings_printed
|
112
113
|
|
113
|
-
|
114
|
+
@out.print " "*@left_margin
|
114
115
|
#column order is set, so go through each column and look up values in the incoming options
|
115
116
|
@column_widths.each_with_index do |column, i|
|
116
117
|
to_print = options[column[:key]] || ""
|
117
118
|
justify = column[:justify] || :left
|
118
119
|
if to_print.is_a? String
|
119
|
-
|
120
|
+
@out.print format(column[:size], normalize(to_print), false, justify)
|
120
121
|
elsif to_print.is_a? Hash
|
121
122
|
color = to_print[:color] || :default
|
122
123
|
background = to_print[:background] || :default
|
@@ -126,31 +127,31 @@ class ConsoleTable
|
|
126
127
|
justify = to_print[:justify] || justify #can override
|
127
128
|
mode = to_print[:mode] || :default
|
128
129
|
|
129
|
-
formatted=format(column[:size], text, ellipsize, justify).colorize(:color=>color, :background=>background, :mode=>mode)
|
130
|
+
formatted=format(column[:size], text, ellipsize, justify).colorize(:color => color, :background => background, :mode => mode)
|
130
131
|
|
131
|
-
unless(to_print[:highlight].nil?)
|
132
|
+
unless (to_print[:highlight].nil?)
|
132
133
|
highlight_regex = to_print[:highlight][:regex] || /wontbefoundbecauseit'sgobbledygookblahblahblahbah/
|
133
134
|
highlight_color = to_print[:highlight][:color] || :blue
|
134
135
|
highlight_background = to_print[:highlight][:background] || :default
|
135
136
|
|
136
|
-
formatted = formatted.gsub(highlight_regex, '\0'.colorize(:color=>highlight_color, :background=>highlight_background))
|
137
|
+
formatted = formatted.gsub(highlight_regex, '\0'.colorize(:color => highlight_color, :background => highlight_background))
|
137
138
|
end
|
138
139
|
|
139
|
-
|
140
|
+
@out.print formatted
|
140
141
|
else
|
141
|
-
|
142
|
+
@out.print format(column[:size], normalize(to_print.to_s))
|
142
143
|
end
|
143
144
|
|
144
|
-
|
145
|
+
@out.print " " if i < @column_widths.size-1
|
145
146
|
end
|
146
|
-
|
147
|
+
@out.print "\n"
|
147
148
|
|
148
149
|
@count = @count + 1
|
149
150
|
end
|
150
151
|
|
151
152
|
private
|
152
153
|
def normalize(string)
|
153
|
-
if
|
154
|
+
if string.nil?
|
154
155
|
nil
|
155
156
|
else
|
156
157
|
string.to_s.gsub(/\s+/, " ").strip #Primarily to remove any tabs or newlines
|
@@ -167,47 +168,44 @@ class ConsoleTable
|
|
167
168
|
end
|
168
169
|
|
169
170
|
num_spacers = @original_column_layout.length - 1
|
170
|
-
set_sizes = @original_column_layout.collect{|x| x[:size]}.find_all{|x| x.is_a? Integer}
|
171
|
+
set_sizes = @original_column_layout.collect { |x| x[:size] }.find_all { |x| x.is_a? Integer }
|
171
172
|
used_up = set_sizes.inject(:+) || 0
|
172
173
|
available = total_width - used_up - @left_margin - @right_margin - num_spacers
|
173
174
|
|
174
|
-
if
|
175
|
-
|
176
|
-
Kernel.exit(-1)
|
175
|
+
if available <= 0
|
176
|
+
raise("ConsoleTable configuration invalid, current window is too small to display required sizes")
|
177
177
|
end
|
178
178
|
|
179
|
-
percentages = @original_column_layout.collect{|x| x[:size]}.find_all{|x| x.is_a? Float}
|
179
|
+
percentages = @original_column_layout.collect { |x| x[:size] }.find_all { |x| x.is_a? Float }
|
180
180
|
percent_used = percentages.inject(:+) || 0
|
181
181
|
|
182
|
-
if
|
183
|
-
|
184
|
-
Kernel.exit(-1)
|
182
|
+
if percent_used > 1.0
|
183
|
+
raise("ConsoleTable configuration invalid, percentages total value greater than 100%")
|
185
184
|
end
|
186
185
|
|
187
186
|
percent_available = 1 - percent_used
|
188
|
-
stars = @original_column_layout.collect{|x| x[:size]}.find_all{|x| x.is_a? String}
|
189
|
-
num_stars = stars.length
|
190
|
-
percent_for_stars = percent_available / num_stars
|
187
|
+
stars = @original_column_layout.collect { |x| x[:size] }.find_all { |x| x.is_a? String }
|
188
|
+
num_stars = [stars.length, 1].max
|
189
|
+
percent_for_stars = percent_available.to_f / num_stars
|
191
190
|
|
192
191
|
@original_column_layout.each do |column_config|
|
193
192
|
if column_config[:size].is_a? Integer
|
194
193
|
@column_widths << column_config #As-is when integer
|
195
194
|
elsif column_config[:size].is_a? Float
|
196
|
-
@column_widths << column_config.merge({:size=> (column_config[:size]*available).floor
|
195
|
+
@column_widths << column_config.merge({:size => (column_config[:size]*available).floor})
|
197
196
|
elsif column_config[:size].is_a?(String) && column_config[:size] == "*"
|
198
|
-
@column_widths << column_config.merge({:size=> (percent_for_stars*available).floor
|
197
|
+
@column_widths << column_config.merge({:size => (percent_for_stars*available).floor})
|
199
198
|
else
|
200
|
-
|
201
|
-
Kernel.exit(-1)
|
199
|
+
raise("ConsoleTable configuration invalid, '#{column_config[:size]}' is not a valid size")
|
202
200
|
end
|
203
201
|
end
|
204
202
|
|
205
|
-
@working_width = (@column_widths.inject(0) {|res, c| res+c[:size]}) + @column_widths.length - 1
|
203
|
+
@working_width = (@column_widths.inject(0) { |res, c| res+c[:size] }) + @column_widths.length - 1
|
206
204
|
end
|
207
205
|
|
208
206
|
def format(length, text, ellipsize=false, justify=:left)
|
209
207
|
if text.length > length
|
210
|
-
if
|
208
|
+
if ellipsize
|
211
209
|
text[0, length-3] + '...'
|
212
210
|
else
|
213
211
|
text[0, length]
|
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require '../lib/console_table'
|
3
|
+
|
4
|
+
class ConsoleTableTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@mock_out = StringIO.new
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
# Do nothing
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_basic
|
16
|
+
ENV["COLUMNS"] = "100"
|
17
|
+
|
18
|
+
commit_table_config = [
|
19
|
+
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
20
|
+
{:key=>:col2, :size=>20, :title=>"Column 2"},
|
21
|
+
]
|
22
|
+
|
23
|
+
ConsoleTable.define(commit_table_config, :output=>@mock_out) do |table|
|
24
|
+
table.print({
|
25
|
+
:col1 => "Row 1, Column 1",
|
26
|
+
:col2 => "Row 1, Column 2"
|
27
|
+
})
|
28
|
+
|
29
|
+
table.print({
|
30
|
+
:col1 => "Row 2, Column 1",
|
31
|
+
:col2 => "Row 2, Column 1"
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
#2345678901234567890##2345678901234567890
|
36
|
+
expected=<<-END
|
37
|
+
=========================================
|
38
|
+
Column 1 Column 2
|
39
|
+
-----------------------------------------
|
40
|
+
Row 1, Column 1 Row 1, Column 2
|
41
|
+
Row 2, Column 1 Row 2, Column 1
|
42
|
+
=========================================
|
43
|
+
END
|
44
|
+
|
45
|
+
assert_output_equal expected, @mock_out.string
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_percents
|
49
|
+
ENV["COLUMNS"] = "100"
|
50
|
+
|
51
|
+
commit_table_config = [
|
52
|
+
{:key=>:col1, :size=>0.3, :title=>"Column 1"},
|
53
|
+
{:key=>:col2, :size=>0.7, :title=>"Column 2"},
|
54
|
+
]
|
55
|
+
|
56
|
+
ConsoleTable.define(commit_table_config, :output=>@mock_out) do |table|
|
57
|
+
table.print({
|
58
|
+
:col1 => "Row 1, Column 1",
|
59
|
+
:col2 => "Row 1, Column 2"
|
60
|
+
})
|
61
|
+
|
62
|
+
table.print({
|
63
|
+
:col1 => "Row 2, Column 1",
|
64
|
+
:col2 => "Row 2, Column 1"
|
65
|
+
})
|
66
|
+
end
|
67
|
+
|
68
|
+
expected=<<-END
|
69
|
+
===================================================================================================
|
70
|
+
Column 1 Column 2
|
71
|
+
---------------------------------------------------------------------------------------------------
|
72
|
+
Row 1, Column 1 Row 1, Column 2
|
73
|
+
Row 2, Column 1 Row 2, Column 1
|
74
|
+
===================================================================================================
|
75
|
+
END
|
76
|
+
|
77
|
+
assert_output_equal expected, @mock_out.string
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_star_fills_all_extra_space
|
81
|
+
ENV["COLUMNS"] = "100"
|
82
|
+
|
83
|
+
commit_table_config = [
|
84
|
+
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
85
|
+
{:key=>:col2, :size=>"*", :title=>"Column 2"},
|
86
|
+
]
|
87
|
+
|
88
|
+
ConsoleTable.define(commit_table_config, :output=>@mock_out) do |table|
|
89
|
+
table.print({
|
90
|
+
:col1 => "Row 1, Column 1",
|
91
|
+
:col2 => "Row 1, Column 2"
|
92
|
+
})
|
93
|
+
|
94
|
+
table.print({
|
95
|
+
:col1 => "Row 2, Column 1",
|
96
|
+
:col2 => "Row 2, Column 1"
|
97
|
+
})
|
98
|
+
end
|
99
|
+
|
100
|
+
expected=<<-END
|
101
|
+
====================================================================================================
|
102
|
+
Column 1 Column 2
|
103
|
+
----------------------------------------------------------------------------------------------------
|
104
|
+
Row 1, Column 1 Row 1, Column 2
|
105
|
+
Row 2, Column 1 Row 2, Column 1
|
106
|
+
====================================================================================================
|
107
|
+
END
|
108
|
+
|
109
|
+
assert_output_equal expected, @mock_out.string
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_multiple_stars_split_evenly
|
113
|
+
ENV["COLUMNS"] = "100"
|
114
|
+
|
115
|
+
commit_table_config = [
|
116
|
+
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
117
|
+
{:key=>:col2, :size=>"*", :title=>"Column 2"},
|
118
|
+
{:key=>:col3, :size=>"*", :title=>"Column 3"},
|
119
|
+
]
|
120
|
+
|
121
|
+
ConsoleTable.define(commit_table_config, :output=>@mock_out) do |table|
|
122
|
+
table.print({
|
123
|
+
:col1 => "Row 1, Column 1",
|
124
|
+
:col2 => "Row 1, Column 2",
|
125
|
+
:col3 => "Row 1, Column 3"
|
126
|
+
})
|
127
|
+
|
128
|
+
table.print({
|
129
|
+
:col1 => "Row 2, Column 1",
|
130
|
+
:col2 => "Row 2, Column 1",
|
131
|
+
:col3 => "Row 2, Column 3"
|
132
|
+
})
|
133
|
+
end
|
134
|
+
|
135
|
+
expected=<<-END
|
136
|
+
====================================================================================================
|
137
|
+
Column 1 Column 2 Column 3
|
138
|
+
----------------------------------------------------------------------------------------------------
|
139
|
+
Row 1, Column 1 Row 1, Column 2 Row 1, Column 3
|
140
|
+
Row 2, Column 1 Row 2, Column 1 Row 2, Column 3
|
141
|
+
====================================================================================================
|
142
|
+
END
|
143
|
+
|
144
|
+
assert_output_equal expected, @mock_out.string
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_can_combine_percentages_fixed_and_stars
|
148
|
+
ENV["COLUMNS"] = "160"
|
149
|
+
|
150
|
+
commit_table_config = [
|
151
|
+
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
152
|
+
{:key=>:col2, :size=>0.3, :title=>"Column 2"},
|
153
|
+
{:key=>:col3, :size=>4, :title=>"Column 3"},
|
154
|
+
{:key=>:col4, :size=>"*", :title=>"Column 4"},
|
155
|
+
{:key=>:col5, :size=>0.2, :title=>"Column 5"},
|
156
|
+
{:key=>:col6, :size=>"*", :title=>"Column 6"},
|
157
|
+
{:key=>:col7, :size=>10, :title=>"Column 7"}
|
158
|
+
]
|
159
|
+
|
160
|
+
ConsoleTable.define(commit_table_config, :output=>@mock_out) do |table|
|
161
|
+
table.print({
|
162
|
+
:col1 => "Row 1, Column 1",
|
163
|
+
:col2 => "Row 1, Column 2",
|
164
|
+
:col3 => "Row 1, Column 3",
|
165
|
+
:col4 => "Row 1, Column 4",
|
166
|
+
:col5 => "Row 1, Column 5",
|
167
|
+
:col6 => "Row 1, Column 6",
|
168
|
+
:col7 => "Row 1, Column 7",
|
169
|
+
})
|
170
|
+
|
171
|
+
table.print({
|
172
|
+
:col1 => "Row 2, Column 1",
|
173
|
+
:col2 => "Row 2, Column 2",
|
174
|
+
:col3 => "Row 2, Column 3",
|
175
|
+
:col4 => "Row 2, Column 4",
|
176
|
+
:col5 => "Row 2, Column 5",
|
177
|
+
:col6 => "Row 2, Column 6",
|
178
|
+
:col7 => "Row 2, Column 7",
|
179
|
+
})
|
180
|
+
end
|
181
|
+
|
182
|
+
expected=<<-END
|
183
|
+
================================================================================================================================================================
|
184
|
+
Column 1 Column 2 Colu Column 4 Column 5 Column 6 Column 7
|
185
|
+
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
186
|
+
Row 1, Column 1 Row 1, Column 2 Row Row 1, Column 4 Row 1, Column 5 Row 1, Column 6 Row 1, Col
|
187
|
+
Row 2, Column 1 Row 2, Column 2 Row Row 2, Column 4 Row 2, Column 5 Row 2, Column 6 Row 2, Col
|
188
|
+
================================================================================================================================================================
|
189
|
+
END
|
190
|
+
|
191
|
+
assert_output_equal expected, @mock_out.string
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_wont_create_layout_too_large_for_screen
|
195
|
+
ENV["COLUMNS"] = "30"
|
196
|
+
|
197
|
+
commit_table_config = [
|
198
|
+
{:key=>:col1, :size=>20, :title=>"Column 1"},
|
199
|
+
{:key=>:col1, :size=>20, :title=>"Column 2"},
|
200
|
+
]
|
201
|
+
|
202
|
+
assert_raise(RuntimeError) { ConsoleTable.define(commit_table_config) }
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_wont_create_layout_with_more_than_100_percent
|
206
|
+
ENV["COLUMNS"] = "30"
|
207
|
+
|
208
|
+
commit_table_config = [
|
209
|
+
{:key=>:col1, :size=>0.8, :title=>"Column 1"},
|
210
|
+
{:key=>:col1, :size=>0.3, :title=>"Column 2"},
|
211
|
+
]
|
212
|
+
|
213
|
+
assert_raise(RuntimeError) { ConsoleTable.define(commit_table_config) }
|
214
|
+
end
|
215
|
+
|
216
|
+
def test_wont_create_layout_with_invalid_size
|
217
|
+
ENV["COLUMNS"] = "30"
|
218
|
+
|
219
|
+
commit_table_config = [
|
220
|
+
{:key=>:col1, :size=>0.8, :title=>"Column 1"},
|
221
|
+
{:key=>:col1, :size=>"hello!", :title=>"Column 2"},
|
222
|
+
]
|
223
|
+
|
224
|
+
assert_raise(RuntimeError) { ConsoleTable.define(commit_table_config) }
|
225
|
+
end
|
226
|
+
|
227
|
+
private
|
228
|
+
def assert_output_equal(expected, actual)
|
229
|
+
expected_lines = expected.split("\n")
|
230
|
+
actual_lines = actual.split("\n")
|
231
|
+
assert_equal expected_lines.length, actual_lines.length
|
232
|
+
expected_lines.each_with_index do |expected_line, i|
|
233
|
+
actual_line = actual_lines[i]
|
234
|
+
assert_equal expected_line.rstrip, actual_line.rstrip
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
end
|
data/todo.txt
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: console_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rod Hilton
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.9'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: colorize
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -68,6 +82,8 @@ files:
|
|
68
82
|
- Rakefile
|
69
83
|
- console_table.gemspec
|
70
84
|
- lib/console_table.rb
|
85
|
+
- test/console_table_test.rb
|
86
|
+
- todo.txt
|
71
87
|
homepage: https://github.com/rodhilton/console_table
|
72
88
|
licenses:
|
73
89
|
- MIT
|
@@ -92,4 +108,5 @@ rubygems_version: 2.2.2
|
|
92
108
|
signing_key:
|
93
109
|
specification_version: 4
|
94
110
|
summary: Simplifies printing tables of information to commandline consoles
|
95
|
-
test_files:
|
111
|
+
test_files:
|
112
|
+
- test/console_table_test.rb
|