table_print 1.5.7 → 1.6.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.
@@ -11,7 +11,86 @@ describe TablePrint::Printer do
11
11
  describe "printing an empty array" do
12
12
  it "returns the string 'no data'" do
13
13
  p = Printer.new([])
14
- p.table_print.should == 'No data.'
14
+ expect(p.table_print).to eq 'No data.'
15
+ end
16
+ end
17
+
18
+ describe "printing strings" do
19
+ it "prints the strings without modifying them" do
20
+ data = ["hello".dup, "world".dup]
21
+ expect(Printer.new(data).table_print).to eq "VALUE\n-----\nhello\nworld"
22
+ expect(data).to eq ["hello", "world"]
23
+ end
24
+
25
+ it "prints strings nested in arrays without modifying them" do
26
+ data = [["hello".dup, "world".dup]]
27
+ expect(Printer.new(data).table_print).to eq "0 | 1 \n------|------\nhello | world"
28
+ expect(data).to eq [["hello", "world"]]
29
+ end
30
+ end
31
+
32
+ describe "printing a hash with keys that aren't strings or symbols" do
33
+ it "finds the values anyway" do
34
+ expect(Printer.new([{1 => "one", 2 => "two"}]).table_print).to eq "1 | 2 \n----|----\none | two"
35
+ end
36
+
37
+ it "leaves string and symbol keyed rows untouched, subclass and all" do
38
+ # A hash subclass gets clobbered by the transform_keys, which we would prefer to avoid when we can
39
+ indifferent = Class.new(Hash) do
40
+ def [](key)
41
+ super(key.to_s)
42
+ end
43
+ end
44
+ row = indifferent.new
45
+ row["author"] = "ryan"
46
+
47
+ # a lambda column gets the row as it was handed to us, so its own lookup still works
48
+ expect(Printer.new([row], [{:include => {:two => lambda { |r| r[:author] * 2 }}}]).table_print).to eq(
49
+ "AUTHOR | TWO \n-------|---------\nryan | ryanryan"
50
+ )
51
+ end
52
+ end
53
+
54
+ describe "several columns named in one options hash" do
55
+ it "applies each one to hash data" do
56
+ rows = [{ :title => "First post!", :author => "Ryan" }]
57
+
58
+ expect(Printer.new(rows, [{ :title => { :max_width => 6 }, :author => { :min_width => 8 } }]).table_print).to eq(
59
+ "TITLE | AUTHOR \n-------|---------\nFir... | Ryan "
60
+ )
61
+ end
62
+
63
+ it "picks and sizes grid columns by index" do
64
+ rows = [[1, "alice", true], [2, "bob", false]]
65
+
66
+ expect(Printer.new(rows, [{ "0" => {}, "2" => {} }]).table_print).to eq(
67
+ "0 | 2 \n--|------\n1 | true \n2 | false"
68
+ )
69
+ end
70
+ end
71
+
72
+ describe "printing an array of arrays" do
73
+ it "prints one row per inner array, with the positions as columns" do
74
+ expect(Printer.new([[1, "alice"], [2, "bob"]]).table_print).to eq "0 | 1 \n--|------\n1 | alice\n2 | bob "
75
+ end
76
+
77
+ it "takes its columns from the first row" do
78
+ # the short row has no cell for column 1; the long row's third cell is not shown
79
+ expect(Printer.new([["a", "b"], ["c"], ["d", "e", "f"]]).table_print).to eq(
80
+ "0 | 1 \n--|---------------\na | b \nc | Method Missing\nd | e "
81
+ )
82
+ end
83
+
84
+ it "lets you address the columns by index" do
85
+ expect(Printer.new([[1, "alice"], [2, "bob"]], ["1"]).table_print).to eq "1 \n-----\nalice\nbob "
86
+ expect(Printer.new([[1, "alice"], [2, "bob"]], [{:except => "0"}]).table_print).to eq "1 \n-----\nalice\nbob "
87
+ end
88
+ end
89
+
90
+ describe "printing a hash" do
91
+ it "prints the hash as one row with its keys as columns" do
92
+ data = {"host" => "db.internal", "user" => "app"}
93
+ expect(Printer.new(data).table_print).to eq "HOST | USER\n------------|-----\ndb.internal | app "
15
94
  end
16
95
  end
17
96
 
@@ -20,14 +99,49 @@ describe TablePrint::Printer do
20
99
  Sandbox.add_class("Blog")
21
100
  Sandbox.add_attributes("Blog", :author)
22
101
  p = Printer.new(Sandbox::Blog.new, "author.name")
23
- p.table_print.should == 'No data.'
102
+ expect(p.table_print).to eq 'No data.'
103
+ end
104
+ end
105
+
106
+ describe "unreachable cells" do
107
+ it "shows the configured value" do
108
+ TablePrint::Config.set(:unreachable_value, ["n/a"])
109
+
110
+ expect(Printer.new([{ :a => 1 }, { :b => 2 }]).table_print).to eq "A \n---\n1 \nn/a"
111
+ ensure
112
+ TablePrint::Config.clear(:unreachable_value)
113
+ end
114
+
115
+ it "leaves the cell blank when the value is nil, keeping the column" do
116
+ TablePrint::Config.set(:unreachable_value, [nil])
117
+
118
+ # one trailing space: the column is still there, the cell is just empty
119
+ expect(Printer.new([{ :a => 1 }, { :b => 2 }]).table_print).to eq "A\n-\n1\n "
120
+ ensure
121
+ TablePrint::Config.clear(:unreachable_value)
122
+ end
123
+ end
124
+
125
+ describe "a class-level config" do
126
+ it "survives being printed more than once" do
127
+ Sandbox.add_class("Blog")
128
+ Sandbox.add_attributes("Blog", :title, :author)
129
+ blogs = [Sandbox::Blog.new(:title => "First post!", :author => "Ryan")]
130
+
131
+ tp.set Sandbox::Blog, :except => :title
132
+
133
+ # resolving the options used to consume them, so the second print ignored the config
134
+ expect(Printer.new(blogs).table_print).to eq "AUTHOR\n------\nRyan "
135
+ expect(Printer.new(blogs).table_print).to eq "AUTHOR\n------\nRyan "
136
+ ensure
137
+ tp.clear Sandbox::Blog
24
138
  end
25
139
  end
26
140
 
27
141
  describe "message" do
28
142
  it "defaults to the time the print took, but in string" do
29
143
  message = Printer.new([]).message
30
- message.should be_a String
144
+ expect(message).to be_a String
31
145
  expect(message.to_f.to_s).to eq(message)
32
146
  end
33
147
 
@@ -36,7 +150,7 @@ describe TablePrint::Printer do
36
150
 
37
151
  tp.set Sandbox::User, :id, :email
38
152
  p = Printer.new(Sandbox::User.new)
39
- p.message.should == "Printed with config"
153
+ expect(p.message).to eq "Printed with config"
40
154
  end
41
155
  end
42
156
 
@@ -48,8 +162,8 @@ describe TablePrint::Printer do
48
162
 
49
163
  p = Printer.new(Sandbox::Post.new)
50
164
  cols = p.send(:columns)
51
- cols.length.should == 1
52
- cols.first.name.should == 'title'
165
+ expect(cols.length).to eq 1
166
+ expect(cols.first.name).to eq 'title'
53
167
  end
54
168
 
55
169
  it 'pull the column names off of the array of Structs' do
@@ -57,8 +171,8 @@ describe TablePrint::Printer do
57
171
  data = [struct.new("User 1", "Familyname 1"), struct.new("User 2", "Familyname 2")]
58
172
  p = Printer.new(data)
59
173
  cols = p.send(:columns)
60
- cols.length.should == 2
61
- cols.collect(&:name).sort.should == ['name', 'surname']
174
+ expect(cols.length).to eq 2
175
+ expect(cols.collect(&:name).sort).to eq ['name', 'surname']
62
176
  end
63
177
 
64
178
  context 'when keys are symbols' do
@@ -71,8 +185,8 @@ describe TablePrint::Printer do
71
185
 
72
186
  p = Printer.new(data)
73
187
  cols = p.send(:columns)
74
- cols.length.should == 2
75
- cols.collect(&:name).sort.should == ['name', 'surname']
188
+ expect(cols.length).to eq 2
189
+ expect(cols.collect(&:name).sort).to eq ['name', 'surname']
76
190
  end
77
191
  end
78
192
 
@@ -86,8 +200,8 @@ describe TablePrint::Printer do
86
200
 
87
201
  p = Printer.new(data)
88
202
  cols = p.send(:columns)
89
- cols.length.should == 2
90
- cols.collect(&:name).sort.should == ['name', 'surname']
203
+ expect(cols.length).to eq 2
204
+ expect(cols.collect(&:name).sort).to eq ['name', 'surname']
91
205
  end
92
206
  end
93
207
 
@@ -97,8 +211,8 @@ describe TablePrint::Printer do
97
211
 
98
212
  p = Printer.new(Sandbox::Post.new, :except => :title)
99
213
  cols = p.send(:columns)
100
- cols.length.should == 1
101
- cols.first.name.should == 'author'
214
+ expect(cols.length).to eq 1
215
+ expect(cols.first.name).to eq 'author'
102
216
  end
103
217
 
104
218
  it "adds included columns" do
@@ -107,9 +221,9 @@ describe TablePrint::Printer do
107
221
 
108
222
  p = Printer.new(Sandbox::Post.new, :include => :author)
109
223
  cols = p.send(:columns)
110
- cols.length.should == 2
111
- cols.first.name.should == 'title'
112
- cols.last.name.should == 'author'
224
+ expect(cols.length).to eq 2
225
+ expect(cols.first.name).to eq 'title'
226
+ expect(cols.last.name).to eq 'author'
113
227
  end
114
228
  end
115
229
  end
data/table_print.gemspec CHANGED
@@ -6,7 +6,6 @@ Gem::Specification.new do |gem|
6
6
 
7
7
  gem.authors = ["Chris Doyle"]
8
8
  gem.email = ["chris@arches.io"]
9
- gem.email = "chris@arches.io"
10
9
 
11
10
  gem.description = "TablePrint turns objects into nicely formatted columns for easy reading. Works great in rails console, works on pure ruby objects, autodetects columns, lets you traverse ActiveRecord associations. Simple, powerful."
12
11
  gem.summary = "Turn objects into nicely formatted columns for easy reading"
@@ -14,12 +13,13 @@ Gem::Specification.new do |gem|
14
13
  gem.version = TablePrint::VERSION
15
14
  gem.license = 'MIT'
16
15
 
17
- gem.files = `git ls-files`.split($\)
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.files = `git ls-files`.split("\n")
19
17
  gem.require_paths = ["lib"]
20
18
 
21
19
  gem.add_development_dependency 'cat', '~> 0.2.1'
22
- gem.add_development_dependency 'cucumber', '~> 2.4.0'
23
- gem.add_development_dependency 'rspec', '~> 2.11.0'
24
- gem.add_development_dependency 'rake', '~> 0.9.2'
20
+ gem.add_development_dependency 'cucumber', '~> 12.0'
21
+ gem.add_development_dependency 'irb', '~> 1.16'
22
+ gem.add_development_dependency 'ostruct', '~> 0.6'
23
+ gem.add_development_dependency 'rake', '~> 13.2'
24
+ gem.add_development_dependency 'rspec', '~> 3.13'
25
25
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.7
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Doyle
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2020-06-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: cat
@@ -30,62 +29,92 @@ dependencies:
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: 2.4.0
32
+ version: '12.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: 2.4.0
39
+ version: '12.0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: rspec
41
+ name: irb
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.16'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.16'
54
+ - !ruby/object:Gem::Dependency
55
+ name: ostruct
43
56
  requirement: !ruby/object:Gem::Requirement
44
57
  requirements:
45
58
  - - "~>"
46
59
  - !ruby/object:Gem::Version
47
- version: 2.11.0
60
+ version: '0.6'
48
61
  type: :development
49
62
  prerelease: false
50
63
  version_requirements: !ruby/object:Gem::Requirement
51
64
  requirements:
52
65
  - - "~>"
53
66
  - !ruby/object:Gem::Version
54
- version: 2.11.0
67
+ version: '0.6'
55
68
  - !ruby/object:Gem::Dependency
56
69
  name: rake
57
70
  requirement: !ruby/object:Gem::Requirement
58
71
  requirements:
59
72
  - - "~>"
60
73
  - !ruby/object:Gem::Version
61
- version: 0.9.2
74
+ version: '13.2'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '13.2'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.13'
62
89
  type: :development
63
90
  prerelease: false
64
91
  version_requirements: !ruby/object:Gem::Requirement
65
92
  requirements:
66
93
  - - "~>"
67
94
  - !ruby/object:Gem::Version
68
- version: 0.9.2
95
+ version: '3.13'
69
96
  description: TablePrint turns objects into nicely formatted columns for easy reading.
70
97
  Works great in rails console, works on pure ruby objects, autodetects columns, lets
71
98
  you traverse ActiveRecord associations. Simple, powerful.
72
- email: chris@arches.io
99
+ email:
100
+ - chris@arches.io
73
101
  executables: []
74
102
  extensions: []
75
103
  extra_rdoc_files: []
76
104
  files:
77
- - ".document"
105
+ - ".github/workflows/ci.yml"
78
106
  - ".gitignore"
79
107
  - ".rspec"
80
- - ".travis.yml"
81
108
  - Gemfile
82
109
  - LICENSE.txt
83
- - README.rdoc
110
+ - README.md
84
111
  - Rakefile
112
+ - bin/console
85
113
  - features/adding_columns.feature
86
114
  - features/configuring_output.feature
87
115
  - features/excluding_columns.feature
88
116
  - features/multibyte.feature
117
+ - features/printing_array.feature
89
118
  - features/printing_hash.feature
90
119
  - features/printing_struct.feature
91
120
  - features/sensible_defaults.feature
@@ -105,6 +134,7 @@ files:
105
134
  - spec/column_spec.rb
106
135
  - spec/config_resolver_spec.rb
107
136
  - spec/config_spec.rb
137
+ - spec/data_shapes_spec.rb
108
138
  - spec/fingerprinter_spec.rb
109
139
  - spec/formatter_spec.rb
110
140
  - spec/hash_extensions_spec.rb
@@ -118,7 +148,6 @@ homepage: http://tableprintgem.com
118
148
  licenses:
119
149
  - MIT
120
150
  metadata: {}
121
- post_install_message:
122
151
  rdoc_options: []
123
152
  require_paths:
124
153
  - lib
@@ -133,28 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
162
  - !ruby/object:Gem::Version
134
163
  version: '0'
135
164
  requirements: []
136
- rubygems_version: 3.0.3
137
- signing_key:
165
+ rubygems_version: 4.0.20
138
166
  specification_version: 4
139
167
  summary: Turn objects into nicely formatted columns for easy reading
140
- test_files:
141
- - features/adding_columns.feature
142
- - features/configuring_output.feature
143
- - features/excluding_columns.feature
144
- - features/multibyte.feature
145
- - features/printing_hash.feature
146
- - features/printing_struct.feature
147
- - features/sensible_defaults.feature
148
- - features/support/step_definitions/before.rb
149
- - features/support/step_definitions/steps.rb
150
- - spec/column_spec.rb
151
- - spec/config_resolver_spec.rb
152
- - spec/config_spec.rb
153
- - spec/fingerprinter_spec.rb
154
- - spec/formatter_spec.rb
155
- - spec/hash_extensions_spec.rb
156
- - spec/printable_spec.rb
157
- - spec/returnable_spec.rb
158
- - spec/row_group_spec.rb
159
- - spec/spec_helper.rb
160
- - spec/table_print_spec.rb
168
+ test_files: []
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.4
4
- - 2.5
5
- - 2.6
6
- - 2.7
7
- - jruby-18mode
8
- - jruby-19mode
9
-
data/README.rdoc DELETED
@@ -1,209 +0,0 @@
1
- = table_print
2
-
3
- {<img src="https://travis-ci.org/arches/table_print.svg?branch=master" />}[http://travis-ci.org/arches/table_print]
4
- {<img src="https://codeclimate.com/github/arches/table_print.png" />}[https://codeclimate.com/github/arches/table_print]
5
-
6
- TablePrint shows objects in nicely formatted columns for easy reading. It even lets you nest other tables
7
- of related objects, contextualizing data across tables. It's incredibly flexible, yet simple, making it easy to
8
- see exactly the data you care about.
9
-
10
- This {three minute screencast}[http://tableprintgem.com] will give you a quick overview of table_print's most
11
- powerful features and how to use them.
12
-
13
- http://arches.io/tp_example.gif
14
-
15
- == Installation
16
-
17
- # Install as a standalone gem
18
- $ gem install table_print
19
-
20
- # Or install within rails
21
- In your Gemfile: gem "table_print"
22
- $ bundle install
23
-
24
- == Usage
25
-
26
- # Outside rails
27
- $ irb
28
- > require 'table_print'
29
- > tp array_of_objects, options
30
-
31
- # Inside rails, the gem has already been required by your Gemfile so all you need to do is
32
- $ rails c
33
- > tp array_of_objects, options
34
-
35
- You should see something like this:
36
-
37
- > tp Book.all
38
- AUTHOR | SUMMARY | TITLE
39
- ------------------|---------------------------------|------------------
40
- Michael Connelly | Another book by Michael Con... | The Fifth Witness
41
- Manning Marable | From acclaimed historian Ma... | Malcolm X
42
- Tina Fey | Worth it. -Trees | Bossypants
43
-
44
- TablePrint tries to use sensible defaults to choose the columns to show. If you're inspecting ActiveRecord objects, it
45
- uses the ActiveRecord column names. You can customize the output to show fewer columns, or show other methods you've written
46
- on your model. Use symbols or strings to reference the columns.
47
-
48
- # Maybe you store a user's hourly rate but you want to see their yearly income
49
- tp User.limit(30), :include => :yearly_income, :except => :hourly_rate
50
-
51
- # Maybe all you care about is their mailing info
52
- tp User.limit(30), :address, 'city', 'state', :zip
53
-
54
- If you're not using ActiveRecord, the TablePrint default is to show all the methods defined directly on your object (nothing
55
- from superclasses/mixins).
56
-
57
- You can reference nested objects with the method chain required to reach them. Say you had some users who wrote books, and those
58
- books had photos.
59
-
60
- > tp Author.limit(3), "name", "books.title", "books.photos.caption"
61
- NAME | BOOKS.TITLE | BOOKS.PHOTOS.CAPTION
62
- ------------------|-------------------|----------------------------------
63
- Michael Connelly | The Fifth Witness | Susan was running, fast, away...
64
- | | Along came a spider.
65
- | Malcolm X |
66
- | Bossypants | Yes! Yes! A thousand times ye...
67
- | | Don't see many like you aroun...
68
- Carrot Top | |
69
- Milton Greene | How I Learned | Once upon a time, I was a sma...
70
- | | Lemons are yellow, limes are ...
71
- | | Never as a woman her age. I l...
72
- | Desperados | Avast.
73
- | | Giraffes lived a peaceful exi...
74
-
75
-
76
- === Column options
77
-
78
- Pass options to individual columns through the options hash by using the display method as the hash key. Eg, if you wanted
79
- a skinny email column, set the width explicitly:
80
-
81
- tp User.all, :email => {:width => 12}
82
- tp User.all, :id, {:email => {:width => 12}}, :age
83
-
84
- Available column options:
85
-
86
- * *display_method* - string/symbol/proc - used to populate the column. Can be a method name or a proc. See below.
87
- * *formatters* - array of objects - each will be called in turn as the cells are printed. Must define a 'format' method. See below.
88
- * *time_format* - string - passed to strftime[http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime], only affects time columns
89
- * *width* - integer - how wide you want your column.
90
- * *display_name* - string - useful if you want spaces in your column name
91
- * *separator* - string - default is vertical bar for console and markdown, change it to a comma for CSV output
92
-
93
- ==== Display method
94
-
95
- Columns are named after hash keys. To rename a column, use the name you want as the key, and pass the method as an option.
96
-
97
- tp User.all, :active => {:display_method => :active_in_the_past_six_months} # the User class defines active_in_the_past_six_months method
98
-
99
- ==== Lambdas
100
-
101
- You can pass a proc as the display_method for a column:
102
-
103
- tp User.all, :email, :monthly_payment, yearly_payment: lambda{|u| u.monthly_payment * 12}
104
-
105
- Or if you want to pass other options along with the lambda:
106
-
107
- tp User.all, :yearly_payment => {:display_method => lambda{|u| u.monthly_payment * 12}, :width => 10}
108
-
109
- Make sure to add curly braces if you have more than one column with a lambda or if this column isn't the last one.
110
-
111
- tp User.all, :email, { daily_payment: lambda { |u| u.monthly_payment / 30} }, :monthly_payment, { yearly_payment: lambda { |u| u.monthly_payment * 12} }
112
-
113
- ==== Column formatters
114
-
115
- Similar to a lambda column, you can use a column formatter to reuse code across prints. Any object with a 'format' method
116
- can be used to filter a column. This could also be used for coloring output.
117
-
118
- class NoNewlineFormatter
119
- def format(value)
120
- value.to_s.gsub(/\r\n/, " ")
121
- end
122
- end
123
-
124
- tp User.all, :bio => {:formatters => [NoNewlineFormatter.new]} # strip newlines from user bios
125
-
126
- === HTML Output
127
-
128
- Currently the best way to show table_print output on an HTML page is using a <pre> tag. You can create a helper
129
- method to send table_print output directly into your <pre> tag:
130
-
131
- def tp_pre data, options={}
132
- content_tag :pre, TablePrint::Printer.new(data, options).table_print
133
- end
134
-
135
- === CSV Output
136
-
137
- Set the column separator to get an output you can save as a CSV:
138
-
139
- tp.set :separator, ","
140
-
141
- Since your CSV viewer probably already handles column widths for you, setting +max_width+ to something very large will help you export your full data set. Otherwise, this CSV output will still be truncated to the default max_width of 30 characters.
142
-
143
- === Config
144
-
145
- Use tp.set and tp.clear to set options on a class-by-class basis.
146
-
147
- tp.set User, :id, :email # now whenever you print users, the only columns shown will be id and email
148
-
149
- > tp User.first
150
- ID | EMAIL
151
- ---|------------
152
- 1 | foo@bar.com
153
-
154
- # the config sets a 'baseline' for each print. You can still include/except columns:
155
- > tp User.first, :except => :email
156
- ID
157
- --
158
- 17
159
-
160
- # a specific set of columns will entirely override the baseline config:
161
- > tp User.first, :first_name
162
- FIRST_NAME
163
- ----------
164
- Phooey
165
-
166
- tp.clear User # back to square one - print all the columns we can find
167
-
168
- To see the config for a given object, use tp.config_for.
169
-
170
- > tp.set User, :id, :email
171
- > tp.config_for User
172
- [:id, :email]
173
-
174
- You can also set global options:
175
-
176
- tp.set :max_width, 10 # columns won't exceed 10 characters
177
- tp.set :time_format, "%Y" # date columns will only show the year
178
- tp.set :capitalize_headers, false # don't capitalize column headers
179
-
180
- You can redirect output:
181
-
182
- f = File.open("users.txt", "w")
183
- tp.set :io, f
184
- tp User.all # written to users.txt instead of STDOUT
185
- tp.clear :io
186
- tp User.all # writing to STDOUT again
187
-
188
- === Multibyte
189
-
190
- Unfortunately, the current approach to finding the width of multibyte strings is too slow. If you're going to be
191
- working with a lot of multibyte characters, set the multibyte option first to enable the slower yet more precise
192
- width calculation:
193
-
194
- > tp.set :multibyte, true
195
-
196
- == Contributing to table_print
197
-
198
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
199
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
200
- * Fork the project
201
- * Start a feature/bugfix branch
202
- * Commit and push until you are happy with your contribution
203
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
204
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
205
-
206
- == Copyright
207
-
208
- Copyright (c) 2013 Chris Doyle. See LICENSE.txt for further details.
209
-