columnist 1.0.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.
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+
3
+ describe Columnist::Table do
4
+ context 'creation' do
5
+ it 'defaults options hash' do
6
+ expect {
7
+ Columnist::Table.new
8
+ }.to_not raise_error
9
+ end
10
+
11
+ it 'defaults the border' do
12
+ expect(Columnist::Table.new.border).to be_false
13
+ end
14
+
15
+ it 'accepts the border' do
16
+ expect(Columnist::Table.new(:border => true).border).to eq(true)
17
+ end
18
+
19
+ it 'defaults the border_color' do
20
+ expect(Columnist::Table.new.border_color).to be_false
21
+ end
22
+
23
+ it 'accepts the border_color' do
24
+ expect(Columnist::Table.new(:border_color => true).border_color).to eq(true)
25
+ end
26
+
27
+ it 'output encoding should be ascii' do
28
+ expect(Columnist::Table.new(:encoding => :ascii).encoding).to eq(:ascii)
29
+ end
30
+
31
+ it 'output encoding should be unicode' do
32
+ expect(Columnist::Table.new.encoding).to eq(:unicode)
33
+ end
34
+ end
35
+
36
+ context 'rows' do
37
+ it 'allows addition' do
38
+ cols = [Columnist::Column.new('test1'), Columnist::Column.new('test2')]
39
+ row = Columnist::Row.new
40
+ cols.each {|c| row.add(c)}
41
+ expect {
42
+ Columnist::Table.new.add(row)
43
+ }.to_not raise_error
44
+ end
45
+
46
+ context 'inherits' do
47
+ before :each do
48
+ @table = Columnist::Table.new
49
+ row = Columnist::Row.new(:color => 'red')
50
+ (
51
+ @cols1 = [
52
+ Columnist::Column.new('asdf', :width => 5),
53
+ Columnist::Column.new('qwer', :align => 'right', :color => 'purple'),
54
+ Columnist::Column.new('tutu', :color => 'green'),
55
+ Columnist::Column.new('uiui', :bold => true),
56
+ ]
57
+ ).each {|c| row.add(c)}
58
+ @table.add(row)
59
+ row = Columnist::Row.new
60
+ (@cols2 = [
61
+ Columnist::Column.new('test'),
62
+ Columnist::Column.new('test'),
63
+ Columnist::Column.new('test', :color => 'blue'),
64
+ Columnist::Column.new('test'),
65
+ ]
66
+ ).each {|c| row.add(c)}
67
+ @table.add(row)
68
+ end
69
+
70
+ it 'positional attributes' do
71
+ [:align, :width, :size, :padding].each do |m|
72
+ 4.times do |i|
73
+ expect(@table.rows[1].columns[i].send(m)).to eq(@table.rows[0].columns[i].send(m))
74
+ end
75
+ end
76
+ end
77
+
78
+ context 'no header row' do
79
+ it 'color' do
80
+ expect(@table.rows[1].columns[0].color).to eq('red')
81
+ expect(@table.rows[1].columns[1].color).to eq('purple')
82
+ expect(@table.rows[1].columns[2].color).to eq('blue')
83
+ expect(@table.rows[1].columns[3].color).to eq('red')
84
+ end
85
+
86
+ it 'bold' do
87
+ expect(@table.rows[1].columns[0].bold).to be_false
88
+ expect(@table.rows[1].columns[1].bold).to be_false
89
+ expect(@table.rows[1].columns[2].bold).to be_false
90
+ expect(@table.rows[1].columns[3].bold).to be_true
91
+ end
92
+ end
93
+
94
+ context 'with header row' do
95
+ before :each do
96
+ @table = Columnist::Table.new
97
+ row = Columnist::Row.new(:header => true)
98
+ @cols1.each {|c| row.add(c)}
99
+ @table.add(row)
100
+ row = Columnist::Row.new
101
+ @cols2.each {|c| row.add(c)}
102
+ @table.add(row)
103
+ end
104
+
105
+ it 'color' do
106
+ expect(@table.rows[1].columns[0].color).to eq('red')
107
+ expect(@table.rows[1].columns[1].color).to eq('purple')
108
+ expect(@table.rows[1].columns[2].color).to eq('blue')
109
+ expect(@table.rows[1].columns[3].color).to eq('red')
110
+ end
111
+
112
+ it 'bold' do
113
+ expect(@table.rows[1].columns[0].bold).to be_false
114
+ expect(@table.rows[1].columns[0].bold).to be_false
115
+ expect(@table.rows[1].columns[1].bold).to be_false
116
+ expect(@table.rows[1].columns[2].bold).to be_false
117
+ expect(@table.rows[1].columns[3].bold).to be_true
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+
124
+ describe '#auto_adjust_widths' do
125
+ it 'sets the widths of each column in each row to the maximum required width for that column' do
126
+ table = Columnist::Table.new.tap do |t|
127
+ t.add(
128
+ Columnist::Row.new.tap do |r|
129
+ r.add Columnist::Column.new('medium length')
130
+ r.add Columnist::Column.new('i am pretty long') # longest column
131
+ r.add Columnist::Column.new('short', :padding => 100)
132
+ end
133
+ )
134
+
135
+ t.add(
136
+ Columnist::Row.new.tap do |r|
137
+ r.add Columnist::Column.new('longer than medium length') # longest column
138
+ r.add Columnist::Column.new('shorter')
139
+ r.add Columnist::Column.new('longer than short') # longest column (inherits padding)
140
+ end
141
+ )
142
+ end
143
+
144
+ table.auto_adjust_widths
145
+
146
+ table.rows.each do |row|
147
+ expect(row.columns[0].width).to eq(Columnist::Column.new('longer than medium length').required_width)
148
+ expect(row.columns[1].width).to eq(Columnist::Column.new('i am pretty long').required_width)
149
+ expect(row.columns[2].width).to eq(Columnist::Column.new('longer than short', :padding => 100).required_width)
150
+ end
151
+ end
152
+ end
153
+
154
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: columnist
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Albert Rannetsperger
8
+ - Wes Bailey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colored
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.2'
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.0
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - "~>"
29
+ - !ruby/object:Gem::Version
30
+ version: '1.2'
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '1.0'
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.0.0
54
+ description: A quick & easy way to generate reports on the the command line
55
+ email: alb3rtuk@hotmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - README.md
61
+ - lib/columnist.rb
62
+ - lib/columnist/column.rb
63
+ - lib/columnist/formatter/nested.rb
64
+ - lib/columnist/formatter/progress.rb
65
+ - lib/columnist/options_validator.rb
66
+ - lib/columnist/row.rb
67
+ - lib/columnist/table.rb
68
+ - spec/column_spec.rb
69
+ - spec/columnist.rb
70
+ - spec/nested_formatter_spec.rb
71
+ - spec/options_validator_spec.rb
72
+ - spec/progress_formatter_spec.rb
73
+ - spec/row_spec.rb
74
+ - spec/spec_helper.rb
75
+ - spec/support/helpers/stdout.rb
76
+ - spec/support/matchers/argument.rb
77
+ - spec/table_spec.rb
78
+ homepage: http://github.com/alb3rtuk/columnist
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A tool for building interactive command line reports
102
+ test_files:
103
+ - spec/column_spec.rb
104
+ - spec/columnist.rb
105
+ - spec/nested_formatter_spec.rb
106
+ - spec/options_validator_spec.rb
107
+ - spec/progress_formatter_spec.rb
108
+ - spec/row_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/support/helpers/stdout.rb
111
+ - spec/support/matchers/argument.rb
112
+ - spec/table_spec.rb