Skip to content

Commit

Permalink
option to set header capitalization
Browse files Browse the repository at this point in the history
  • Loading branch information
arches committed Jul 7, 2014
1 parent e382331 commit e5fc964
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
15 changes: 15 additions & 0 deletions features/configuring_output.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,18 @@ Feature: Configuring output
------
Ryan
"""

Scenario: Setting a lowecase column name
Given a class named Blog

Given Blog has attributes title, author

When I instantiate a Blog with {:title => "post!", :author => 'Ryan'}
And I configure capitalize_headers with false
And table_print Blog, {:author => {:display_name => "Wom Bat"}}
Then the output should contain
"""
Wom Bat
-------
Ryan
"""
1 change: 1 addition & 0 deletions features/support/step_definitions/before.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Before do
Sandbox.cleanup!
TablePrint::Config.clear(:capitalize_headers)
end
4 changes: 4 additions & 0 deletions features/support/step_definitions/steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
TablePrint::Config.set(:multibyte, [value == "true"])
end

When /^I configure capitalize_headers with (.*)$/ do |value|
TablePrint::Config.set(:capitalize_headers, [value == "true"])
end

When /^configure (.*) with (.*)$/ do |klass, config|
klass = Sandbox.const_get_from_string(klass)
TablePrint::Config.set(klass, eval(config))
Expand Down
10 changes: 10 additions & 0 deletions lib/table_print/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ class Config
DEFAULT_MAX_WIDTH = 30
DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
DEFAULT_IO = STDOUT
DEFAULT_CAPITALIZE_HEADERS = true

@@max_width = DEFAULT_MAX_WIDTH
@@time_format = DEFAULT_TIME_FORMAT
@@multibyte = false
@@io = STDOUT
@@capitalize_headers = true

@@klasses = {}

Expand Down Expand Up @@ -57,6 +59,14 @@ def self.time_format=(format)
@@time_format = format
end

def self.capitalize_headers
@@capitalize_headers
end

def self.capitalize_headers=(caps)
@@capitalize_headers = caps
end

def self.io
@@io
end
Expand Down
5 changes: 4 additions & 1 deletion lib/table_print/row_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ def header
f.format(column.name)
end

padded_names.join(" | ").upcase
header_string = padded_names.join(" | ")
header_string.upcase! if TablePrint::Config.capitalize_headers

header_string
end

def add_formatter(name, formatter)
Expand Down

0 comments on commit e5fc964

Please sign in to comment.