table_print 1.4.1 → 1.5.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.
- checksums.yaml +8 -8
- data/README.rdoc +8 -0
- data/features/sensible_defaults.feature +16 -0
- data/lib/table_print.rb +9 -1
- data/lib/table_print/config_resolver.rb +1 -1
- data/lib/table_print/printable.rb +5 -2
- data/lib/table_print/row_group.rb +3 -3
- data/lib/table_print/version.rb +1 -1
- data/spec/row_group_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZTQ1ZjViN2VjOGYxYWYyYjRlN2U5NzM1NzExNzg5YjYxYjk1NzEwNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWY1ZGU3OGRmNzQ0OGZiNDRmZmNkYjUyYzRkNjlkN2VjZmQ0MmI5MA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTYxZjUwNjFhYzdlYzViODJmOWViMzE1ODRjMzU0OGQ5ZjlhZjkwOWYwZjRm
|
10
|
+
NjY4ZmUxNWI4ODljNWQ0YWIyOWQ1MGZkMmNmNWI2ZWJhOTMxNDQ3MzgyNTZi
|
11
|
+
MjE5NGMwOTdiMGNlOTE1YTc1YzA4ZDk4MGQxNTA4M2ZmNDBmOGI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2NlZTk0MWNlNzlkNDExNGJkNDZjZWFiNjI1YmE2OTA5NjIwYTdkMTliYThm
|
14
|
+
NDExNTU4YzVhMWJmY2FiZDgxNzcxMjQwOTA3NzE5YTAxNDRmY2ZjODk0Mzc2
|
15
|
+
NzIxNDk2YTA2MDQ5ODVkNWM2YTMwNDE0ZTk1YmJmYTA3NDE5MGE=
|
data/README.rdoc
CHANGED
@@ -151,6 +151,14 @@ You can also set global options:
|
|
151
151
|
|
152
152
|
tp.set :max_width, 10 # columns won't exceed 10 characters
|
153
153
|
tp.set :time_format, "%Y" # date columns will only show the year
|
154
|
+
|
155
|
+
=== Multibyte
|
156
|
+
|
157
|
+
Unfortunately, the current approach to finding the width of multibyte strings is too slow. If you're going to be
|
158
|
+
working with a lot of multibyte characters, set the multibyte option first to enable the slower yet more precise
|
159
|
+
width calculation:
|
160
|
+
|
161
|
+
> tp.set :multibyte, true
|
154
162
|
|
155
163
|
== Contributing to table_print
|
156
164
|
|
@@ -84,3 +84,19 @@ Feature: Sensible defaults
|
|
84
84
|
-----------
|
85
85
|
First post!
|
86
86
|
"""
|
87
|
+
|
88
|
+
Scenario: An object with field info (like a Mongoid object)
|
89
|
+
Given a class named Mongoid
|
90
|
+
|
91
|
+
Given a class named Blog
|
92
|
+
Given Blog has attributes title, author
|
93
|
+
Given Blog has a method named fields with lambda{{"title" => Sandbox::Mongoid.new}}
|
94
|
+
|
95
|
+
When I instantiate a Blog with {:title => "First post!", :author => 'Ryan'}
|
96
|
+
And table_print Blog
|
97
|
+
Then the output should contain
|
98
|
+
"""
|
99
|
+
TITLE
|
100
|
+
-----------
|
101
|
+
First post!
|
102
|
+
"""
|
data/lib/table_print.rb
CHANGED
@@ -25,19 +25,27 @@ module TablePrint
|
|
25
25
|
|
26
26
|
def table_print
|
27
27
|
return "No data." if @data.empty?
|
28
|
+
|
29
|
+
# it's groups all the way down
|
30
|
+
# make a top-level group to hold everything we're about to do
|
28
31
|
group = TablePrint::RowGroup.new
|
32
|
+
|
33
|
+
# parse the config and attach it to the group
|
29
34
|
columns.each do |c|
|
30
|
-
group.set_column(c
|
35
|
+
group.set_column(c)
|
31
36
|
end
|
32
37
|
|
38
|
+
# copy data from original objects into the group
|
33
39
|
group_data = (@data.first.is_a?(Hash) || @data.first.is_a?(Struct)) ? [@data] : @data
|
34
40
|
group_data.each do |data|
|
35
41
|
group.add_children(Fingerprinter.new.lift(columns, data))
|
36
42
|
end
|
37
43
|
|
44
|
+
# munge the tree of data we created, to condense the output
|
38
45
|
group.collapse!
|
39
46
|
return "No data." if group.columns.empty?
|
40
47
|
|
48
|
+
# turn everything into a string for output
|
41
49
|
[group.header, group.horizontal_separator, group.format].join("\n")
|
42
50
|
end
|
43
51
|
|
@@ -3,10 +3,13 @@ module TablePrint
|
|
3
3
|
# Sniff the data class for non-standard methods to use as a baseline for display
|
4
4
|
def self.default_display_methods(target)
|
5
5
|
return target.class.columns.collect(&:name) if target.class.respond_to? :columns
|
6
|
-
|
6
|
+
|
7
|
+
# eg mongoid
|
8
|
+
return target.fields.keys if target.respond_to? :fields and target.fields.is_a? Hash
|
9
|
+
|
7
10
|
return target.keys if target.is_a? Hash
|
8
11
|
return target.members.collect(&:to_sym) if target.is_a? Struct
|
9
|
-
|
12
|
+
|
10
13
|
methods = []
|
11
14
|
target.methods.each do |method_name|
|
12
15
|
method = target.method(method_name)
|
@@ -30,9 +30,9 @@ module TablePrint
|
|
30
30
|
@children.length
|
31
31
|
end
|
32
32
|
|
33
|
-
def set_column(
|
34
|
-
return parent.set_column(
|
35
|
-
@columns[name.to_s] = column
|
33
|
+
def set_column(column)
|
34
|
+
return parent.set_column(column) if parent
|
35
|
+
@columns[column.name.to_s] = column
|
36
36
|
end
|
37
37
|
|
38
38
|
def columns
|
data/lib/table_print/version.rb
CHANGED
data/spec/row_group_spec.rb
CHANGED
@@ -8,8 +8,8 @@ describe RowRecursion do
|
|
8
8
|
|
9
9
|
describe "#set_column" do
|
10
10
|
it "assigns the column object to the column name" do
|
11
|
-
column = Column.new
|
12
|
-
parent.set_column(
|
11
|
+
column = Column.new(:name => "foobar")
|
12
|
+
parent.set_column(column)
|
13
13
|
parent.column_for(:foobar).should == column
|
14
14
|
end
|
15
15
|
end
|
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.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cat
|