command_line_reporter 2.1 → 3.0
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/README.md +29 -7
- data/examples/nested.rb +2 -2
- data/examples/progress.rb +10 -8
- data/examples/quiet.rb +1 -1
- data/examples/simple.rb +2 -1
- data/examples/table.rb +38 -16
- data/lib/column.rb +52 -35
- data/lib/command_line_reporter.rb +39 -25
- data/lib/nested_formatter.rb +20 -5
- data/lib/progress_formatter.rb +17 -2
- data/lib/row.rb +64 -46
- data/lib/table.rb +42 -28
- data/lib/version.rb +1 -1
- data/spec/column_spec.rb +342 -49
- data/spec/command_line_reporter_spec.rb +104 -3
- data/spec/nested_formatter_spec.rb +44 -3
- data/spec/progress_formatter_spec.rb +26 -0
- data/spec/row_spec.rb +47 -10
- data/spec/table_spec.rb +73 -19
- metadata +14 -3
data/lib/row.rb
CHANGED
@@ -1,60 +1,78 @@
|
|
1
1
|
require 'column'
|
2
|
-
require '
|
2
|
+
require 'options_validator'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module CommandLineReporter
|
5
|
+
class Row
|
6
|
+
include OptionsValidator
|
6
7
|
|
7
|
-
|
8
|
+
VALID_OPTIONS = [:header, :color, :bold]
|
9
|
+
attr_accessor :columns, :border, *VALID_OPTIONS
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
self.border = false
|
12
|
-
end
|
11
|
+
def initialize(options = {})
|
12
|
+
self.validate_options(options, *VALID_OPTIONS)
|
13
13
|
|
14
|
-
|
14
|
+
self.columns = []
|
15
|
+
self.border = false
|
16
|
+
self.header = options[:header] || false
|
17
|
+
self.color = options[:color]
|
18
|
+
self.bold = options[:bold] || false
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
18
|
-
|
21
|
+
def add(column)
|
22
|
+
if column.color.nil? && self.color
|
23
|
+
column.color = self.color
|
24
|
+
end
|
25
|
+
|
26
|
+
if self.bold || self.header
|
27
|
+
column.bold = true
|
28
|
+
end
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
30
|
+
self.columns << column
|
31
|
+
end
|
32
|
+
|
33
|
+
def separator
|
34
|
+
@sep ||= '+' + self.columns.map {|c| '-' * (c.width + 2)}.join('+') + '+'
|
35
|
+
end
|
36
|
+
|
37
|
+
def output
|
38
|
+
screen_count.times do |sr|
|
39
|
+
line = (self.border) ? '| ' : ''
|
40
|
+
self.columns.size.times do |mc|
|
41
|
+
col = self.columns[mc]
|
42
|
+
# Account for the fact that some columns will have more screen rows than their
|
43
|
+
# counterparts in the row. An example being:
|
44
|
+
# c1 = Column.new('x' * 50, :width => 10)
|
45
|
+
# c2 = Column.new('x' * 20, :width => 10)
|
46
|
+
#
|
47
|
+
# c1.screen_rows.size == 5
|
48
|
+
# c2.screen_rows.size == 2
|
49
|
+
#
|
50
|
+
# So when we don't have a screen row for c2 we need to fill the screen with the
|
51
|
+
# proper number of blanks so the layout looks like (parenthesis on the right just
|
52
|
+
# indicate screen row index)
|
53
|
+
#
|
54
|
+
# +-------------+------------+
|
55
|
+
# | xxxxxxxxxxx | xxxxxxxxxx | (0)
|
56
|
+
# | xxxxxxxxxxx | xxxxxxxxxx | (1)
|
57
|
+
# | xxxxxxxxxxx | | (2)
|
58
|
+
# | xxxxxxxxxxx | | (3)
|
59
|
+
# | xxxxxxxxxxx | | (4)
|
60
|
+
# +-------------+------------+
|
61
|
+
if col.screen_rows[sr].nil?
|
62
|
+
line << ' ' * col.width
|
63
|
+
else
|
64
|
+
line << self.columns[mc].screen_rows[sr]
|
65
|
+
end
|
66
|
+
line << ' ' + ((self.border) ? '| ' : '')
|
48
67
|
end
|
49
|
-
line
|
68
|
+
puts line
|
50
69
|
end
|
51
|
-
puts line
|
52
70
|
end
|
53
|
-
end
|
54
71
|
|
55
|
-
|
72
|
+
private
|
56
73
|
|
57
|
-
|
58
|
-
|
74
|
+
def screen_count
|
75
|
+
@sc ||= self.columns.inject(0) {|max,column| column.screen_rows.size > max ? column.screen_rows.size : max}
|
76
|
+
end
|
59
77
|
end
|
60
78
|
end
|
data/lib/table.rb
CHANGED
@@ -1,44 +1,58 @@
|
|
1
1
|
require 'row'
|
2
2
|
require 'options_validator'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
module CommandLineReporter
|
5
|
+
class Table
|
6
|
+
include OptionsValidator
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
VALID_OPTIONS = [:border]
|
9
|
+
attr_accessor :rows, *VALID_OPTIONS
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def initialize(options = {})
|
12
|
+
self.validate_options(options, *VALID_OPTIONS)
|
12
13
|
|
13
|
-
|
14
|
+
self.border = options[:border] || false
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
@rows = []
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
def add(row)
|
20
|
+
# Inheritance from the table
|
21
|
+
row.border = self.border
|
22
|
+
|
23
|
+
# Inherit properties from the first row
|
24
|
+
if self.rows[0]
|
25
|
+
row.columns.each_with_index do |c,i|
|
26
|
+
# The positional attributes are always required to inheret to make sure the table
|
27
|
+
# displays properly
|
28
|
+
c.align = self.rows[0].columns[i].align
|
29
|
+
c.padding = self.rows[0].columns[i].padding
|
30
|
+
c.width = self.rows[0].columns[i].width
|
31
|
+
c.size = c.width - 2 * c.padding
|
32
|
+
|
33
|
+
# Allow for the fact that the row or column may take precedence
|
34
|
+
unless self.rows[0].header || row.color || c.color
|
35
|
+
c.color = self.rows[0].columns[i].color
|
36
|
+
end
|
37
|
+
|
38
|
+
# Allow for the row to take precendence
|
39
|
+
unless self.rows[0].header || row.bold
|
40
|
+
c.bold = self.rows[0].columns[i].bold
|
41
|
+
end
|
42
|
+
end
|
29
43
|
end
|
30
|
-
end
|
31
44
|
|
32
|
-
|
33
|
-
|
45
|
+
self.rows << row
|
46
|
+
end
|
34
47
|
|
35
|
-
|
36
|
-
|
48
|
+
def output
|
49
|
+
return if self.rows.size == 0 # we got here with nothing to print to the screen
|
37
50
|
|
38
|
-
puts self.rows[0].separator if self.border
|
39
|
-
self.rows.each do |row|
|
40
|
-
row.output
|
41
51
|
puts self.rows[0].separator if self.border
|
52
|
+
self.rows.each do |row|
|
53
|
+
row.output
|
54
|
+
puts self.rows[0].separator if self.border
|
55
|
+
end
|
42
56
|
end
|
43
57
|
end
|
44
58
|
end
|
data/lib/version.rb
CHANGED