table_print 1.5.5 → 1.5.6
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 +4 -4
- data/README.rdoc +9 -0
- data/features/configuring_output.feature +16 -1
- data/features/support/step_definitions/before.rb +1 -0
- data/features/support/step_definitions/steps.rb +4 -0
- data/lib/table_print/config.rb +10 -0
- data/lib/table_print/row_group.rb +3 -3
- data/lib/table_print/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f888ea5f3cd53aae3450eda4e53f9bd649a940a
|
4
|
+
data.tar.gz: eaee7c7975d8b875a5a13290a89e1eca4797cbd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb84a8749506b7a8de69471157e56f0584ce3183c644df5e7c9bcdac6b7b30220b4baf9cf6b1f6f473b75ec924fa982167ce5888ae544927a2d867090613627
|
7
|
+
data.tar.gz: 433a4425650c26e68452b63edcc014c8018cf90cdf036972e130720fffa0b9120d8e4fbc83d182a99a191a0f1216d74ef2428adf42c10b72f4ab712a5a6bdc74
|
data/README.rdoc
CHANGED
@@ -88,6 +88,7 @@ Available column options:
|
|
88
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
89
|
* *width* - integer - how wide you want your column.
|
90
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
|
91
92
|
|
92
93
|
==== Display method
|
93
94
|
|
@@ -131,6 +132,14 @@ method to send table_print output directly into your <pre> tag:
|
|
131
132
|
content_tag :pre, TablePrint::Printer.new(data, options).table_print
|
132
133
|
end
|
133
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
|
+
|
134
143
|
=== Config
|
135
144
|
|
136
145
|
Use tp.set and tp.clear to set options on a class-by-class basis.
|
@@ -99,7 +99,7 @@ Feature: Configuring output
|
|
99
99
|
Ryan
|
100
100
|
"""
|
101
101
|
|
102
|
-
Scenario: Setting a
|
102
|
+
Scenario: Setting a lowercase column name
|
103
103
|
Given a class named Blog
|
104
104
|
|
105
105
|
Given Blog has attributes title, author
|
@@ -113,3 +113,18 @@ Feature: Configuring output
|
|
113
113
|
-------
|
114
114
|
Ryan
|
115
115
|
"""
|
116
|
+
|
117
|
+
Scenario: Setting the column separator
|
118
|
+
Given a class named Blog
|
119
|
+
|
120
|
+
Given Blog has attributes title, author
|
121
|
+
|
122
|
+
When I instantiate a Blog with {:title => "post!", :author => 'Ryan'}
|
123
|
+
And I configure separator with ','
|
124
|
+
And table_print Blog
|
125
|
+
Then the output should contain
|
126
|
+
"""
|
127
|
+
TITLE , AUTHOR
|
128
|
+
------,-------
|
129
|
+
post! , Ryan
|
130
|
+
"""
|
@@ -66,6 +66,10 @@ When /^I configure capitalize_headers with (.*)$/ do |value|
|
|
66
66
|
TablePrint::Config.set(:capitalize_headers, [value == "true"])
|
67
67
|
end
|
68
68
|
|
69
|
+
When /^I configure separator with '(.*)'$/ do |value|
|
70
|
+
TablePrint::Config.set(:separator, [value])
|
71
|
+
end
|
72
|
+
|
69
73
|
When /^configure (.*) with (.*)$/ do |klass, config|
|
70
74
|
klass = Sandbox.const_get_from_string(klass)
|
71
75
|
TablePrint::Config.set(klass, eval(config))
|
data/lib/table_print/config.rb
CHANGED
@@ -5,12 +5,14 @@ module TablePrint
|
|
5
5
|
DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
6
6
|
DEFAULT_IO = $stdout
|
7
7
|
DEFAULT_CAPITALIZE_HEADERS = true
|
8
|
+
DEFAULT_SEPARATOR = "|"
|
8
9
|
|
9
10
|
@@max_width = DEFAULT_MAX_WIDTH
|
10
11
|
@@time_format = DEFAULT_TIME_FORMAT
|
11
12
|
@@multibyte = false
|
12
13
|
@@io = DEFAULT_IO
|
13
14
|
@@capitalize_headers = true
|
15
|
+
@@separator = DEFAULT_SEPARATOR
|
14
16
|
|
15
17
|
@@klasses = {}
|
16
18
|
|
@@ -67,6 +69,14 @@ module TablePrint
|
|
67
69
|
@@capitalize_headers = caps
|
68
70
|
end
|
69
71
|
|
72
|
+
def self.separator
|
73
|
+
@@separator
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.separator=(separator)
|
77
|
+
@@separator = separator
|
78
|
+
end
|
79
|
+
|
70
80
|
def self.io
|
71
81
|
@@io
|
72
82
|
end
|
@@ -64,7 +64,7 @@ module TablePrint
|
|
64
64
|
def horizontal_separator
|
65
65
|
columns.collect do |column|
|
66
66
|
'-' * column.width
|
67
|
-
end.join(
|
67
|
+
end.join("-#{TablePrint::Config.separator}-")
|
68
68
|
end
|
69
69
|
|
70
70
|
def header
|
@@ -73,7 +73,7 @@ module TablePrint
|
|
73
73
|
f.format(column.name)
|
74
74
|
end
|
75
75
|
|
76
|
-
header_string = padded_names.join("
|
76
|
+
header_string = padded_names.join(" #{TablePrint::Config.separator} ")
|
77
77
|
header_string.upcase! if TablePrint::Config.capitalize_headers
|
78
78
|
|
79
79
|
header_string
|
@@ -177,7 +177,7 @@ module TablePrint
|
|
177
177
|
def format
|
178
178
|
column_names = columns.collect(&:name)
|
179
179
|
|
180
|
-
output = [column_names.collect { |name| apply_formatters(name, @cells[name]) }.join("
|
180
|
+
output = [column_names.collect { |name| apply_formatters(name, @cells[name]) }.join(" #{TablePrint::Config.separator} ")]
|
181
181
|
output.concat @children.collect { |g| g.format }
|
182
182
|
|
183
183
|
output.join("\n")
|
data/lib/table_print/version.rb
CHANGED
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.
|
4
|
+
version: 1.5.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cat
|