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/lib/row.rb CHANGED
@@ -1,60 +1,78 @@
1
1
  require 'column'
2
- require 'forwardable'
2
+ require 'options_validator'
3
3
 
4
- class Row
5
- extend Forwardable
4
+ module CommandLineReporter
5
+ class Row
6
+ include OptionsValidator
6
7
 
7
- attr_accessor :columns, :border
8
+ VALID_OPTIONS = [:header, :color, :bold]
9
+ attr_accessor :columns, :border, *VALID_OPTIONS
8
10
 
9
- def initialize(options = {})
10
- self.columns = []
11
- self.border = false
12
- end
11
+ def initialize(options = {})
12
+ self.validate_options(options, *VALID_OPTIONS)
13
13
 
14
- def_delegator :@columns, :push, :add
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
- def separator
17
- @sep ||= '+' + self.columns.map {|c| '-' * (c.width + 2)}.join('+') + '+'
18
- end
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
- def output
21
- screen_count.times do |sr|
22
- line = (self.border) ? '| ' : ''
23
- self.columns.size.times do |mc|
24
- col = self.columns[mc]
25
- # Account for the fact that some columns will have more screen rows than their
26
- # counterparts in the row. An example being:
27
- # c1 = Column.new('x' * 50, :width => 10)
28
- # c2 = Column.new('x' * 20, :width => 10)
29
- #
30
- # c1.screen_rows.size == 5
31
- # c2.screen_rows.size == 2
32
- #
33
- # So when we don't have a screen row for c2 we need to fill the screen with the
34
- # proper number of blanks so the layout looks like (parenthesis on the right just
35
- # indicate screen row index)
36
- #
37
- # +-------------+------------+
38
- # | xxxxxxxxxxx | xxxxxxxxxx | (0)
39
- # | xxxxxxxxxxx | xxxxxxxxxx | (1)
40
- # | xxxxxxxxxxx | | (2)
41
- # | xxxxxxxxxxx | | (3)
42
- # | xxxxxxxxxxx | | (4)
43
- # +-------------+------------+
44
- if col.screen_rows[sr].nil?
45
- line << ' ' * col.width
46
- else
47
- line << self.columns[mc].screen_rows[sr]
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 << ' ' + ((self.border) ? '| ' : '')
68
+ puts line
50
69
  end
51
- puts line
52
70
  end
53
- end
54
71
 
55
- private
72
+ private
56
73
 
57
- def screen_count
58
- @sc ||= self.columns.inject(0) {|max,column| column.screen_rows.size > max ? column.screen_rows.size : max}
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
- class Table
5
- include OptionsValidator
4
+ module CommandLineReporter
5
+ class Table
6
+ include OptionsValidator
6
7
 
7
- VALID_OPTIONS = [:border]
8
- attr_accessor :rows, *VALID_OPTIONS
8
+ VALID_OPTIONS = [:border]
9
+ attr_accessor :rows, *VALID_OPTIONS
9
10
 
10
- def initialize(options = {})
11
- self.validate_options(options, *VALID_OPTIONS)
11
+ def initialize(options = {})
12
+ self.validate_options(options, *VALID_OPTIONS)
12
13
 
13
- self.border = options[:border] || false
14
+ self.border = options[:border] || false
14
15
 
15
- @rows = []
16
- end
16
+ @rows = []
17
+ end
17
18
 
18
- def add(row)
19
- # Inheritance from the table
20
- row.border = self.border
21
-
22
- # Inherit properties from the first row
23
- if self.rows[0]
24
- row.columns.each_with_index do |c,i|
25
- c.align = self.rows[0].columns[i].align
26
- c.padding = self.rows[0].columns[i].padding
27
- c.width = self.rows[0].columns[i].width
28
- c.size = c.width - 2 * c.padding
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
- self.rows << row
33
- end
45
+ self.rows << row
46
+ end
34
47
 
35
- def output
36
- return if self.rows.size == 0 # we got here with nothing to print to the screen
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
@@ -1,3 +1,3 @@
1
1
  module CommandLineReporter
2
- VERSION = '2.1'
2
+ VERSION = '3.0'
3
3
  end