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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWE4N2E1NDljNGIwMDVkMjBkZWM2ZmRmNDlhZjBiYWQzOTQ4ZTZiOQ==
4
+ ZTQ1ZjViN2VjOGYxYWYyYjRlN2U5NzM1NzExNzg5YjYxYjk1NzEwNA==
5
5
  data.tar.gz: !binary |-
6
- YzI3NTg0NGNmNjg2Y2Q4NGE4MWIzNzZjNmVkY2Y1YWI1YjBhOTJkZg==
6
+ NWY1ZGU3OGRmNzQ0OGZiNDRmZmNkYjUyYzRkNjlkN2VjZmQ0MmI5MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- Y2I2NDQyM2NjZDVkZDkzNzNkNmE1NTM5ODM5NDE1NDYzYzU0OGEwMjM0NmUy
10
- N2EzM2M5YWFmYTE2ZDM2Njc1ZGU1OWQxYjJhNGI1NWE2MmNlYWVkYWY1NmMz
11
- OTA2NjY2Mzk0MTZkNmM3M2M1ZDQwZGFhYzY1ZTJlZDEzNTUyNjA=
9
+ MTYxZjUwNjFhYzdlYzViODJmOWViMzE1ODRjMzU0OGQ5ZjlhZjkwOWYwZjRm
10
+ NjY4ZmUxNWI4ODljNWQ0YWIyOWQ1MGZkMmNmNWI2ZWJhOTMxNDQ3MzgyNTZi
11
+ MjE5NGMwOTdiMGNlOTE1YTc1YzA4ZDk4MGQxNTA4M2ZmNDBmOGI=
12
12
  data.tar.gz: !binary |-
13
- ZmYzZWNmNjEwMGZkYTI2NGQ1MzY0ZDFlODBlNGQwMjk5YTEyYzgyMmQ4YzM5
14
- ZWNlYmE1Y2EyYTRhNzg2ZGU2MzY4ZDM0NWU4ZGJlZWQ3Yjg0ODM3MzU4ODJm
15
- NGVhYmYxY2M5YmE5NzAxMzNkODc1MjlkN2ZlZjE4Zjc4OWE1Yzg=
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.name, 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
 
@@ -23,7 +23,7 @@ module TablePrint
23
23
  @included_columns.concat [get_and_remove(options, :include)].flatten
24
24
  @included_columns.map! do |option|
25
25
  if option.is_a? Column
26
- option if option.is_a? Column
26
+ option
27
27
  else
28
28
  option_to_column(option)
29
29
  end
@@ -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(name, column)
34
- return parent.set_column(name, column) if parent
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
@@ -1,4 +1,4 @@
1
1
  module TablePrint
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
4
4
 
@@ -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(:foobar, 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.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-10-31 00:00:00.000000000 Z
11
+ date: 2013-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cat