command_line_reporter 3.1.0 → 3.2.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 CHANGED
@@ -8,9 +8,10 @@ interface to your application. Some of the best features include:
8
8
  * Table syntax similar to HTML that makes it trivial to format your data in rows and columns
9
9
  * Easily created headers and footers for your report
10
10
  * Output suppression that makes it easy for your script to support a _quiet_ flag
11
+ * Capture report output as a string
11
12
 
12
- The latest release also supports colors allowing you to distinguish data in new ways including bold
13
- if your terminal supports it.
13
+ The latest release uses unicode drawing characters for the table, colors allowing you to distinguish
14
+ data in new ways including bold if your terminal supports it.
14
15
 
15
16
  ### Installation
16
17
 
@@ -106,6 +107,9 @@ There are several methods the mixin provides that do not depend on the formatter
106
107
  * :align - Allowed values are left|right|center
107
108
  * :color - The color to use for the terminal output i.e. 'red' or 'blue' or 'green'
108
109
  * :bold - true|false to boldface the font
110
+ * _suppress_output_ - Suppresses output stream that goes to STDOUT
111
+ * _capture_output_ - Captures all of the output stream to a string and restores output to STDOUT
112
+ * _restore_output_ - Restores the output stream to STDOUT
109
113
 
110
114
  ### To Do
111
115
 
@@ -115,6 +119,8 @@ There are several methods the mixin provides that do not depend on the formatter
115
119
 
116
120
  ### Contributors
117
121
 
122
+ * Thanks to [Stefan Frank](https://github.com/mugwump) for raising the issue that he could not
123
+ capture report output in a variable as a string
118
124
  * Thanks to [Mike Gunderloy](https://github.com/ffmike) for suggesting the need for suppressing
119
125
  output and putting together a fantastic pull request and discussion
120
126
  * Thanks to [Jason Rogers](https://github.com/jacaetevha) and [Peter
data/examples/table.rb CHANGED
@@ -34,7 +34,7 @@ class Example
34
34
  column 'CITY', :width => 15
35
35
  end
36
36
  row :color => 'green', :bold => true do
37
- column 'Ceaser'
37
+ column 'caeser'
38
38
  column '1 Appian Way'
39
39
  column 'Rome'
40
40
  end
@@ -55,7 +55,7 @@ class Example
55
55
  column 'CITY', :width => 15
56
56
  end
57
57
  row :color => 'green', :bold => true do
58
- column 'Ceaser'
58
+ column 'caeser'
59
59
  column '1 Appian Way'
60
60
  column 'Rome'
61
61
  end
data/lib/row.rb CHANGED
@@ -30,13 +30,10 @@ module CommandLineReporter
30
30
  self.columns << column
31
31
  end
32
32
 
33
- def separator
34
- @sep ||= '+' + self.columns.map {|c| '-' * (c.width + 2)}.join('+') + '+'
35
- end
36
-
37
33
  def output
38
34
  screen_count.times do |sr|
39
- line = (self.border) ? '| ' : ''
35
+ border_char = ("\u2501" == "u2501") ? '|' : "\u2503"
36
+ line = (self.border) ? "#{border_char} " : ''
40
37
  self.columns.size.times do |mc|
41
38
  col = self.columns[mc]
42
39
  # Account for the fact that some columns will have more screen rows than their
@@ -63,7 +60,7 @@ module CommandLineReporter
63
60
  else
64
61
  line << self.columns[mc].screen_rows[sr]
65
62
  end
66
- line << ' ' + ((self.border) ? '| ' : '')
63
+ line << ' ' + ((self.border) ? "#{border_char} " : '')
67
64
  end
68
65
  puts line
69
66
  end
data/lib/table.rb CHANGED
@@ -30,14 +30,24 @@ module CommandLineReporter
30
30
  c.width = self.rows[0].columns[i].width
31
31
  c.size = c.width - 2 * c.padding
32
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
33
+ # Allow for the fact that the row or column may take precedence and that the first
34
+ # row might be a header row which we don't want to inherit from
35
+ unless row.color || c.color
36
+ if self.rows[0].header
37
+ c.color = self.rows[1].columns[i].color if self.rows[1]
38
+ else
39
+ c.color = self.rows[0].columns[i].color
40
+ end
36
41
  end
37
42
 
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
43
+ # Allow for the row to take precendence and that the first # row might be a header
44
+ # row which we don't want to inherit from
45
+ unless row.bold
46
+ if self.rows[0].header
47
+ c.bold = self.rows[1].columns[i].bold if self.rows[1]
48
+ else
49
+ c.bold = self.rows[0].columns[i].bold
50
+ end
41
51
  end
42
52
  end
43
53
  end
@@ -48,11 +58,39 @@ module CommandLineReporter
48
58
  def output
49
59
  return if self.rows.size == 0 # we got here with nothing to print to the screen
50
60
 
51
- puts self.rows[0].separator if self.border
52
- self.rows.each do |row|
61
+ puts separator('first') if self.border
62
+ self.rows.each_with_index do |row, index|
53
63
  row.output
54
- puts self.rows[0].separator if self.border
64
+ puts separator('middle') if self.border && (index != self.rows.size - 1)
55
65
  end
66
+ puts separator('last') if self.border
67
+ end
68
+
69
+ private
70
+
71
+ def separator(type = 'middle')
72
+ if "\u2501" == 'u2501'
73
+ left = right = center = '+'
74
+ bar = '-'
75
+ else
76
+ bar = "\u2501"
77
+ case type
78
+ when 'first'
79
+ left = "\u250F"
80
+ center = "\u2533"
81
+ right = "\u2513"
82
+ when 'middle'
83
+ left = "\u2523"
84
+ center = "\u254A"
85
+ right = "\u252B"
86
+ when 'last'
87
+ left = "\u2517"
88
+ center = "\u253B"
89
+ right = "\u251B"
90
+ end
91
+ end
92
+
93
+ left + self.rows[0].columns.map {|c| bar * (c.width + 2)}.join(center) + right
56
94
  end
57
95
  end
58
96
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CommandLineReporter
2
- VERSION = '3.1.0'
2
+ VERSION = '3.2.0'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: command_line_reporter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.1.0
5
+ version: 3.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Wes
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-02-21 00:00:00 Z
14
+ date: 2012-02-26 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -82,7 +82,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- hash: -339870674346797653
85
+ hash: -3704234342160057856
86
86
  segments:
87
87
  - 0
88
88
  version: "0"