table_print 1.5.2 → 1.5.3

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTViMjhhZmQ0MTQ4MjAzOWE2YjY3YmQzYzMyMjNkMmNiYzI5MzFhZg==
4
+ NjkzNmMxZmM1NWY0ZGU2MjQzNGM5MzMyZTQwNmEwZTk2ZjYzMjlkMA==
5
5
  data.tar.gz: !binary |-
6
- M2U2ZGI4ZjA1OTUyOWY1YTY1OGVhY2Q4OWE5NWY3YWJhMWFiNTdkOQ==
6
+ MzIyMzFmODY2M2Q1ZWE4MGRlMTU4NGU5OWRhNmQxNzU5OThiYjMzNA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NWRlZGRjZmY5ZWY1OWU0YzYxODdhNmJkMzAwZjdhOGU3MGY2MjhiY2UxZmY3
10
- M2Q3OTVmZGMyZDI3MTE0NDJiZjNkZjkxNzM4MjFhMmIzNWIxYWE0NWYwZGY4
11
- OGM3ZmU5MzliYmI1M2I2MTg1Y2YxMTcxOTk4ZmY3OTk4NjAxYzQ=
9
+ OTEzNDUyMjA4NWZjZTIyMTk3NTU3ODI5YmU3N2Q0NzY4MTcwYTFjZTNiMDUx
10
+ ZTNhN2E2MzEyODJiMGVkMDgwOGMxOGIwZjRiMDBhNTM0ZDMwZTgyMWY2MWM0
11
+ YTBmNGQ5MjY2N2Q4YjY4OTQxMDRlNTNiMDJmODhhMmE1OTJlNzM=
12
12
  data.tar.gz: !binary |-
13
- Y2QzYTFiOWQ2ZmQyMTJjZDE3OWQ5ZDQyNzFhOTc2MjI1MjNkZmQ1ZGJhMGMx
14
- ZTViYWRlNTI4MTNmMDYzMmYyMDU4OTE5ODQ2ZDRmMzM1Y2NjZDc5NTJiNzI0
15
- NzU4OGE2MGQwYTM0ZjRlYjhlODBlYWIyZTU0OTFmYzNkZjdlZWM=
13
+ ZmZhMmVmMGJlMmQ1MTA2NGM0MjgxNjE3MTkxMWJiZTg5MzdlOTBmN2FmOTUz
14
+ YjA5OWNlODE3ZmU5N2JhNzQ2NzE4OWYxMTY2ZjYzOGVlM2Y1ZTAzZDdjN2Mw
15
+ YzZjNDVjNzQzMWI0OGViOGU1MmEwODY4MTJmYWViZmI4MDc0OGI=
data/.travis.yml CHANGED
@@ -6,7 +6,6 @@ rvm:
6
6
  - 2.0.0
7
7
  - jruby-18mode
8
8
  - jruby-19mode
9
- - rbx-18mode
10
- - rbx-19mode
9
+ - rbx-2
11
10
  - ree
12
11
 
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec :name => 'table_print'
4
4
 
data/README.rdoc CHANGED
@@ -85,6 +85,7 @@ Available column options:
85
85
  * *formatters* - array of objects - each will be called in turn as the cells are printed. Must define a 'format' method. See below.
86
86
  * *time_format* - string - passed to strftime[http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime], only affects time columns
87
87
  * *width* - integer - how wide you want your column.
88
+ * *display_name* - string - useful if you want spaces in your column name
88
89
 
89
90
  ==== Display method
90
91
 
@@ -151,6 +152,15 @@ You can also set global options:
151
152
 
152
153
  tp.set :max_width, 10 # columns won't exceed 10 characters
153
154
  tp.set :time_format, "%Y" # date columns will only show the year
155
+ tp.set :capitalize_headers, false # don't capitalize column headers
156
+
157
+ You can redirect output:
158
+
159
+ f = File.open("users.txt", "w")
160
+ tp.set :io, f
161
+ tp User.all # written to users.txt instead of STDOUT
162
+ tp.clear :io
163
+ tp User.all # writing to STDOUT again
154
164
 
155
165
  === Multibyte
156
166
 
@@ -55,3 +55,18 @@ Feature: Configuring output
55
55
  ------
56
56
  Ryan
57
57
  """
58
+
59
+ Scenario: Setting a lowecase column name
60
+ Given a class named Blog
61
+
62
+ Given Blog has attributes title, author
63
+
64
+ When I instantiate a Blog with {:title => "post!", :author => 'Ryan'}
65
+ And I configure capitalize_headers with false
66
+ And table_print Blog, {:author => {:display_name => "Wom Bat"}}
67
+ Then the output should contain
68
+ """
69
+ Wom Bat
70
+ -------
71
+ Ryan
72
+ """
@@ -1,3 +1,4 @@
1
1
  Before do
2
2
  Sandbox.cleanup!
3
+ TablePrint::Config.clear(:capitalize_headers)
3
4
  end
@@ -62,6 +62,10 @@ When /^I configure multibyte with (.*)$/ do |value|
62
62
  TablePrint::Config.set(:multibyte, [value == "true"])
63
63
  end
64
64
 
65
+ When /^I configure capitalize_headers with (.*)$/ do |value|
66
+ TablePrint::Config.set(:capitalize_headers, [value == "true"])
67
+ end
68
+
65
69
  When /^configure (.*) with (.*)$/ do |klass, config|
66
70
  klass = Sandbox.const_get_from_string(klass)
67
71
  TablePrint::Config.set(klass, eval(config))
@@ -4,11 +4,13 @@ module TablePrint
4
4
  DEFAULT_MAX_WIDTH = 30
5
5
  DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
6
6
  DEFAULT_IO = STDOUT
7
+ DEFAULT_CAPITALIZE_HEADERS = true
7
8
 
8
9
  @@max_width = DEFAULT_MAX_WIDTH
9
10
  @@time_format = DEFAULT_TIME_FORMAT
10
11
  @@multibyte = false
11
12
  @@io = STDOUT
13
+ @@capitalize_headers = true
12
14
 
13
15
  @@klasses = {}
14
16
 
@@ -57,6 +59,14 @@ module TablePrint
57
59
  @@time_format = format
58
60
  end
59
61
 
62
+ def self.capitalize_headers
63
+ @@capitalize_headers
64
+ end
65
+
66
+ def self.capitalize_headers=(caps)
67
+ @@capitalize_headers = caps
68
+ end
69
+
60
70
  def self.io
61
71
  @@io
62
72
  end
@@ -73,6 +73,11 @@ module TablePrint
73
73
  option[:default_width] = option.delete(:width)
74
74
  end
75
75
 
76
+ if option.has_key? :display_name
77
+ option[:display_method] = option[:name]
78
+ option[:name] = option.delete(:display_name)
79
+ end
80
+
76
81
  c = Column.new(option)
77
82
  @column_hash[c.name] = c
78
83
  c
@@ -73,7 +73,10 @@ module TablePrint
73
73
  f.format(column.name)
74
74
  end
75
75
 
76
- padded_names.join(" | ").upcase
76
+ header_string = padded_names.join(" | ")
77
+ header_string.upcase! if TablePrint::Config.capitalize_headers
78
+
79
+ header_string
77
80
  end
78
81
 
79
82
  def add_formatter(name, formatter)
@@ -1,4 +1,4 @@
1
1
  module TablePrint
2
- VERSION = "1.5.2"
2
+ VERSION = "1.5.3"
3
3
  end
4
4
 
@@ -206,6 +206,14 @@ describe TablePrint::ConfigResolver do
206
206
  c.columns.first.formatters.should == [f1, f2]
207
207
  end
208
208
  end
209
+ context "display_name" do
210
+ it "sets the display name on the column" do
211
+ c = TablePrint::ConfigResolver.new(Object, [], :title => {:display_name => "Ti Tle"})
212
+ c.columns.length.should == 1
213
+ c.columns.first.name.should == 'Ti Tle'
214
+ c.columns.first.display_method.should == "title"
215
+ end
216
+ end
209
217
  end
210
218
 
211
219
  describe "#option_to_column" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_print
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Doyle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-10 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cat