command_line_reporter 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/table_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'table'
3
2
 
4
3
  describe CommandLineReporter::Table do
5
4
  context 'creation' do
@@ -10,11 +9,19 @@ describe CommandLineReporter::Table do
10
9
  end
11
10
 
12
11
  it 'defaults the border' do
13
- CommandLineReporter::Table.new.border.should be_false
12
+ expect(CommandLineReporter::Table.new.border).to be_false
14
13
  end
15
14
 
16
15
  it 'accepts the border' do
17
- CommandLineReporter::Table.new(:border => true).border.should == true
16
+ expect(CommandLineReporter::Table.new(:border => true).border).to eq(true)
17
+ end
18
+
19
+ it 'output encoding should be ascii' do
20
+ expect(CommandLineReporter::Table.new(:encoding => :ascii).encoding).to eq(:ascii)
21
+ end
22
+
23
+ it 'output encoding should be unicode' do
24
+ expect(CommandLineReporter::Table.new.encoding).to eq(:unicode)
18
25
  end
19
26
  end
20
27
 
@@ -55,24 +62,24 @@ describe CommandLineReporter::Table do
55
62
  it 'positional attributes' do
56
63
  [:align, :width, :size, :padding].each do |m|
57
64
  4.times do |i|
58
- @table.rows[1].columns[i].send(m).should == @table.rows[0].columns[i].send(m)
65
+ expect(@table.rows[1].columns[i].send(m)).to eq(@table.rows[0].columns[i].send(m))
59
66
  end
60
67
  end
61
68
  end
62
69
 
63
70
  context 'no header row' do
64
71
  it 'color' do
65
- @table.rows[1].columns[0].color.should == 'red'
66
- @table.rows[1].columns[1].color.should == 'purple'
67
- @table.rows[1].columns[2].color.should == 'blue'
68
- @table.rows[1].columns[3].color.should == 'red'
72
+ expect(@table.rows[1].columns[0].color).to eq('red')
73
+ expect(@table.rows[1].columns[1].color).to eq('purple')
74
+ expect(@table.rows[1].columns[2].color).to eq('blue')
75
+ expect(@table.rows[1].columns[3].color).to eq('red')
69
76
  end
70
77
 
71
78
  it 'bold' do
72
- @table.rows[1].columns[0].bold.should be_false
73
- @table.rows[1].columns[1].bold.should be_false
74
- @table.rows[1].columns[2].bold.should be_false
75
- @table.rows[1].columns[3].bold.should be_true
79
+ expect(@table.rows[1].columns[0].bold).to be_false
80
+ expect(@table.rows[1].columns[1].bold).to be_false
81
+ expect(@table.rows[1].columns[2].bold).to be_false
82
+ expect(@table.rows[1].columns[3].bold).to be_true
76
83
  end
77
84
  end
78
85
 
@@ -88,12 +95,43 @@ describe CommandLineReporter::Table do
88
95
  end
89
96
 
90
97
  it 'bold' do
91
- @table.rows[1].columns[0].bold.should be_false
92
- @table.rows[1].columns[1].bold.should be_false
93
- @table.rows[1].columns[2].bold.should be_false
94
- @table.rows[1].columns[3].bold.should be_true
98
+ expect(@table.rows[1].columns[0].bold).to be_false
99
+ expect(@table.rows[1].columns[1].bold).to be_false
100
+ expect(@table.rows[1].columns[2].bold).to be_false
101
+ expect(@table.rows[1].columns[3].bold).to be_true
95
102
  end
96
103
  end
97
104
  end
98
105
  end
106
+
107
+ describe '#auto_adjust_widths' do
108
+ it 'sets the widths of each column in each row to the maximum required width for that column' do
109
+ table = CommandLineReporter::Table.new.tap do |t|
110
+ t.add(
111
+ CommandLineReporter::Row.new.tap do |r|
112
+ r.add CommandLineReporter::Column.new('medium length')
113
+ r.add CommandLineReporter::Column.new('i am pretty long') # longest column
114
+ r.add CommandLineReporter::Column.new('short', :padding => 100)
115
+ end
116
+ )
117
+
118
+ t.add(
119
+ CommandLineReporter::Row.new.tap do |r|
120
+ r.add CommandLineReporter::Column.new('longer than medium length') # longest column
121
+ r.add CommandLineReporter::Column.new('shorter')
122
+ r.add CommandLineReporter::Column.new('longer than short') # longest column (inherits padding)
123
+ end
124
+ )
125
+ end
126
+
127
+ table.auto_adjust_widths
128
+
129
+ table.rows.each do |row|
130
+ expect(row.columns[0].width).to eq(CommandLineReporter::Column.new('longer than medium length').required_width)
131
+ expect(row.columns[1].width).to eq(CommandLineReporter::Column.new('i am pretty long').required_width)
132
+ expect(row.columns[2].width).to eq(CommandLineReporter::Column.new('longer than short', :padding => 100).required_width)
133
+ end
134
+ end
135
+ end
136
+
99
137
  end
metadata CHANGED
@@ -1,64 +1,64 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: command_line_reporter
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.3.0
4
5
  prerelease:
5
- version: 3.2.1
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Wes
9
9
  - Bailey
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2012-02-27 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2014-02-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: bundler
18
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
19
18
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
23
22
  version: 1.0.0
24
23
  type: :development
25
24
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.0.0
31
+ - !ruby/object:Gem::Dependency
28
32
  name: colored
29
- requirement: &id002 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
30
34
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "1.2"
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '1.2'
35
39
  type: :runtime
36
40
  prerelease: false
37
- version_requirements: *id002
38
- description: This gem makes it easy to provide a report while your ruby script is executing
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '1.2'
47
+ description: This gem makes it easy to provide a report while your ruby script is
48
+ executing
39
49
  email: baywes@gmail.com
40
50
  executables: []
41
-
42
51
  extensions: []
43
-
44
52
  extra_rdoc_files: []
45
-
46
- files:
47
- - examples/capture.rb
48
- - examples/nested.rb
49
- - examples/progress.rb
50
- - examples/quiet.rb
51
- - examples/simple.rb
52
- - examples/table.rb
53
- - examples/variable.rb
54
- - lib/column.rb
53
+ files:
54
+ - lib/command_line_reporter/column.rb
55
+ - lib/command_line_reporter/formatter/nested.rb
56
+ - lib/command_line_reporter/formatter/progress.rb
57
+ - lib/command_line_reporter/options_validator.rb
58
+ - lib/command_line_reporter/row.rb
59
+ - lib/command_line_reporter/table.rb
60
+ - lib/command_line_reporter/version.rb
55
61
  - lib/command_line_reporter.rb
56
- - lib/nested_formatter.rb
57
- - lib/options_validator.rb
58
- - lib/progress_formatter.rb
59
- - lib/row.rb
60
- - lib/table.rb
61
- - lib/version.rb
62
62
  - README.md
63
63
  - spec/column_spec.rb
64
64
  - spec/command_line_reporter_spec.rb
@@ -72,35 +72,32 @@ files:
72
72
  - spec/table_spec.rb
73
73
  homepage: http://github.com/wbailey/command_line_reporter
74
74
  licenses: []
75
-
76
75
  post_install_message:
77
76
  rdoc_options: []
78
-
79
- require_paths:
77
+ require_paths:
80
78
  - lib
81
- required_ruby_version: !ruby/object:Gem::Requirement
79
+ required_ruby_version: !ruby/object:Gem::Requirement
82
80
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: -637477018686189691
87
- segments:
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ segments:
88
86
  - 0
89
- version: "0"
90
- required_rubygems_version: !ruby/object:Gem::Requirement
87
+ hash: -3116512959293506911
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
89
  none: false
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- version: "0"
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
96
94
  requirements: []
97
-
98
95
  rubyforge_project:
99
- rubygems_version: 1.8.15
96
+ rubygems_version: 1.8.25
100
97
  signing_key:
101
98
  specification_version: 3
102
99
  summary: A tool for providing interactive command line applications
103
- test_files:
100
+ test_files:
104
101
  - spec/column_spec.rb
105
102
  - spec/command_line_reporter_spec.rb
106
103
  - spec/nested_formatter_spec.rb
data/examples/capture.rb DELETED
@@ -1,32 +0,0 @@
1
- require 'command_line_reporter'
2
-
3
- class Example
4
- include CommandLineReporter
5
-
6
- def run
7
- suppress_output
8
-
9
- table :border => true do
10
- row :color => 'red' do
11
- column 'MY NAME IS REALLY LONG AND WILL WRAP AND HOPE', :width => 20, :align => 'center', :color => 'blue'
12
- column 'ADDRESS', :width => 30, :padding => 5
13
- column 'CITY', :width => 15
14
- end
15
- row :color => 'green', :bold => true do
16
- column 'caeser'
17
- column '1 Appian Way'
18
- column 'Rome'
19
- end
20
- row do
21
- column 'Richard Feynman'
22
- column '1 Golden Gate'
23
- column 'Quantum Field'
24
- end
25
- end
26
-
27
- return capture_output
28
- end
29
- end
30
-
31
- # All the content is now in the report variable
32
- report = Example.new.run
data/examples/nested.rb DELETED
@@ -1,38 +0,0 @@
1
- require 'command_line_reporter'
2
-
3
- class Example
4
- include CommandLineReporter
5
-
6
- def initialize
7
- self.formatter = 'nested'
8
- self.formatter.complete_string = 'done'
9
- end
10
-
11
- def run
12
- x,y,z = 0,0,0
13
-
14
- report(:message => 'calculating first expression') do
15
- x = 2 + 2
16
- sleep 1
17
-
18
- 2.times do
19
- report(:message => 'calculating second expression') do
20
- y = 10 - x
21
- sleep 1
22
-
23
- 10.times do |i|
24
- report(:message => 'pixelizing', :type => 'inline', :complete => "#{i*10+10}%") do
25
- z = x + y
26
- sleep 1
27
- end
28
- end
29
- end
30
- end
31
- end
32
-
33
- horizontal_rule(:width => 20)
34
- %w(x y z).each {|v| aligned "#{v}: #{eval v}"}
35
- end
36
- end
37
-
38
- Example.new.run
data/examples/progress.rb DELETED
@@ -1,68 +0,0 @@
1
- require 'command_line_reporter'
2
-
3
- class Example
4
- include CommandLineReporter
5
-
6
- NYAN_CHARS = "****[;::;<](^-^)"
7
-
8
- def initialize
9
- self.formatter = 'progress'
10
- end
11
-
12
- def run
13
- x = 0
14
-
15
- report do
16
- 10.times do
17
- x += 1
18
- sleep 0.1
19
- # formatter.progress
20
- progress
21
-
22
- 10.times do
23
- x += 1
24
- sleep 0.1
25
- # formatter.progress
26
- progress
27
- end
28
- end
29
- end
30
-
31
- y = 0
32
-
33
- report do
34
- 10.times do
35
- y += 1
36
- sleep 0.1
37
- progress("#{y*10}%")
38
- end
39
- end
40
-
41
- report do
42
- 3.times do
43
- progress("\\")
44
- sleep 0.1
45
- progress("/")
46
- sleep 0.1
47
- progress("-")
48
- sleep 0.1
49
- end
50
- end
51
-
52
- report(:color => 'red') do
53
- 100.times do
54
- progress(erase_chars + NYAN_CHARS)
55
- sleep 0.1
56
- end
57
- end
58
-
59
- aligned "x: #{x}"
60
- aligned "y: #{y}"
61
- end
62
-
63
- def erase_chars
64
- "\10" * NYAN_CHARS.size + " "
65
- end
66
- end
67
-
68
- Example.new.run
data/examples/quiet.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'command_line_reporter'
2
- require 'ostruct'
3
- require 'optparse'
4
-
5
- class Example
6
- include CommandLineReporter
7
-
8
- def initialize
9
- self.formatter = 'progress'
10
- end
11
-
12
- def run(options = {})
13
- x = 0
14
-
15
- suppress_output if options.quiet
16
-
17
- report do
18
- 10.times do
19
- x += 1
20
- sleep 0.1
21
- progress
22
- end
23
- end
24
-
25
- restore_output if options.quiet
26
- end
27
- end
28
-
29
-
30
- options = OpenStruct.new({:quiet => false})
31
-
32
- OptionParser.new do |opts|
33
- opts.banner = "Usage: ruby -I lib example/quiet.rb [-q|--quiet]"
34
-
35
- opts.on('-q', '--quiet', 'do not print any output') do
36
- options.quiet = true
37
- end
38
- end.parse!
39
-
40
- Example.new.run(options)
data/examples/simple.rb DELETED
@@ -1,23 +0,0 @@
1
- require 'command_line_reporter'
2
-
3
- include CommandLineReporter
4
-
5
- class Example
6
- def initialize
7
- self.formatter = 'progress'
8
- end
9
-
10
- def run
11
- report do
12
- sum = 0
13
- 10.times do
14
- sum += 10
15
- progress
16
- end
17
- vertical_spacing
18
- aligned("Sum: #{sum}")
19
- end
20
- end
21
- end
22
-
23
- Example.new.run
data/examples/table.rb DELETED
@@ -1,71 +0,0 @@
1
- # recoil <co>mmand_<li>ne_<re>porter
2
- require 'command_line_reporter'
3
-
4
- class Example
5
- include CommandLineReporter
6
-
7
- def run
8
- header(:title => 'TABLE EXAMPLES - Borders, Wrapping, Alignment and Padding', :align => 'center', :width => 70)
9
-
10
- 2.times do |j|
11
- header :title => "Table #{j}", :align => 'center', :width => 65
12
-
13
- table :border => j % 2 == 0 do
14
- 3.times do
15
- row do
16
- i = 0
17
- 3.times do
18
- i += 10
19
- column 'x' * (0 + rand(50)), :align => %w[left right center][rand(3)], :width => i, :padding => rand(5)
20
- end
21
- end
22
- end
23
- end
24
-
25
- vertical_spacing 2
26
- end
27
-
28
- header :title => 'An example of a table with a header row. The color and border properties are not inherited'
29
-
30
- table :border => true do
31
- row :header => true, :color => 'red' do
32
- column 'MY NAME IS REALLY LONG AND WILL WRAP AND HOPE', :width => 20, :align => 'center', :color => 'blue'
33
- column 'ADDRESS', :width => 30, :padding => 5
34
- column 'CITY', :width => 15
35
- end
36
- row :color => 'green', :bold => true do
37
- column 'caeser'
38
- column '1 Appian Way'
39
- column 'Rome'
40
- end
41
- row do
42
- column 'Richard Feynman'
43
- column '1 Golden Gate'
44
- column 'Quantum Field'
45
- end
46
- end
47
-
48
- vertical_spacing 2
49
- header :title => 'The same table with the properties inherited from the first row'
50
-
51
- table :border => true do
52
- row :color => 'red' do
53
- column 'MY NAME IS REALLY LONG AND WILL WRAP AND HOPE', :width => 20, :align => 'center', :color => 'blue'
54
- column 'ADDRESS', :width => 30, :padding => 5
55
- column 'CITY', :width => 15
56
- end
57
- row :color => 'green', :bold => true do
58
- column 'caeser'
59
- column '1 Appian Way'
60
- column 'Rome'
61
- end
62
- row do
63
- column 'Richard Feynman'
64
- column '1 Golden Gate'
65
- column 'Quantum Field'
66
- end
67
- end
68
- end
69
- end
70
-
71
- Example.new.run
data/examples/variable.rb DELETED
@@ -1,30 +0,0 @@
1
- require 'command_line_reporter'
2
-
3
- include CommandLineReporter
4
-
5
- class Example
6
- def initialize
7
- self.formatter = 'progress'
8
- end
9
-
10
- def run
11
- suppress_output
12
-
13
- report do
14
- sum = 0
15
- 10.times do
16
- sum += 10
17
- progress
18
- end
19
- vertical_spacing
20
- aligned("Sum: #{sum}")
21
- end
22
-
23
- capture_output
24
- end
25
- end
26
-
27
- out = Example.new.run
28
-
29
- puts 'this could be stored in a database'
30
- puts out
data/lib/table.rb DELETED
@@ -1,96 +0,0 @@
1
- require 'row'
2
- require 'options_validator'
3
-
4
- module CommandLineReporter
5
- class Table
6
- include OptionsValidator
7
-
8
- VALID_OPTIONS = [:border]
9
- attr_accessor :rows, *VALID_OPTIONS
10
-
11
- def initialize(options = {})
12
- self.validate_options(options, *VALID_OPTIONS)
13
-
14
- self.border = options[:border] || false
15
-
16
- @rows = []
17
- end
18
-
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 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
41
- end
42
-
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
51
- end
52
- end
53
- end
54
-
55
- self.rows << row
56
- end
57
-
58
- def output
59
- return if self.rows.size == 0 # we got here with nothing to print to the screen
60
-
61
- puts separator('first') if self.border
62
- self.rows.each_with_index do |row, index|
63
- row.output
64
- puts separator('middle') if self.border && (index != self.rows.size - 1)
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
94
- end
95
- end
96
- end