table_print 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/table_print.rb +10 -37
  3. data/table_print.gemspec +8 -8
  4. metadata +14 -16
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -1,6 +1,5 @@
1
1
  # future work:
2
2
  #
3
- # handle multi-level includes like 'tp User.all, :include => "blogs.title"' and ActiveRecord associations
4
3
  # allow other output venues besides 'puts'
5
4
  # allow fine-grained formatting
6
5
  # on-the-fly column definitions (pass a proc as an include, eg 'tp User.all, :include => {:column_name => "Zodiac", :display_method => lambda {|u| find_zodiac_sign(u.birthday)}}')
@@ -16,12 +15,12 @@ class TablePrint
16
15
 
17
16
  # We need this set of built-in types when we determine the default display methods for a given object
18
17
  OBJECT_CLASSES = [String, Bignum, Regexp, ThreadError, Numeric, SystemStackError, IndexError,
19
- SecurityError, SizedQueue, IO, Range, Object, Exception, NoMethodError, TypeError, Integer, Dir,
18
+ SecurityError, IO, Range, Object, Exception, NoMethodError, TypeError, Integer, Dir,
20
19
  ZeroDivisionError, Kernel, RegexpError, SystemExit, NotImplementedError, Hash,
21
20
  Interrupt, SyntaxError, Enumerable, Struct, Class, Continuation, IOError, Proc,
22
21
  RangeError, Data, Thread, Array, NoMemoryError, Time, MatchData,
23
- ConditionVariable, Method, Mutex, StopIteration, Comparable, ArgumentError, Float,
24
- FloatDomainError, UnboundMethod, ThreadGroup, Precision, RuntimeError, FalseClass, Fixnum, Queue,
22
+ Method, StopIteration, Comparable, ArgumentError, Float,
23
+ FloatDomainError, UnboundMethod, ThreadGroup, Precision, RuntimeError, FalseClass, Fixnum,
25
24
  StandardError, EOFError, LoadError, NameError, NilClass, TrueClass, MatchingData,
26
25
  LocalJumpError, Binding, SignalException, SystemCallError, File, ScriptError, Module, Symbol]
27
26
 
@@ -37,7 +36,7 @@ class TablePrint
37
36
 
38
37
  self.separator = options[:separator] || " | "
39
38
 
40
- stack = wrap(data).compact
39
+ stack = Array(data).compact
41
40
 
42
41
  if stack.empty?
43
42
  return "No data."
@@ -122,12 +121,12 @@ class TablePrint
122
121
  # :cascade - show all methods in child objects
123
122
 
124
123
  if options.has_key? :only
125
- display_methods = wrap(options[:only]).map { |m| m.to_s }
124
+ display_methods = Array(options[:only]).map { |m| m.to_s }
126
125
  return display_methods if display_methods.length > 0
127
126
  else
128
127
  display_methods = get_default_display_methods(data_obj) # start with what we can deduce
129
- display_methods.concat(wrap(options[:include])).map! { |m| m.to_s } # add the includes
130
- display_methods = (display_methods - wrap(options[:except]).map! { |m| m.to_s }) # remove the excepts
128
+ display_methods.concat(Array(options[:include])).map! { |m| m.to_s } # add the includes
129
+ display_methods = (display_methods - Array(options[:except]).map! { |m| m.to_s }) # remove the excepts
131
130
  end
132
131
 
133
132
  display_methods.uniq.compact
@@ -151,23 +150,9 @@ class TablePrint
151
150
  methods
152
151
  end
153
152
 
154
- # borrowed from rails
155
- # turn objects into an array
156
- # TODO: this method is duped, put it someplace everyone can see it
157
- def wrap(object)
158
- if object.nil?
159
- []
160
- elsif object.respond_to?(:to_ary)
161
- object.to_ary
162
- else
163
- [object]
164
- end
165
- end
166
-
167
153
  class ColumnHelper
168
154
  attr_accessor :field_length, :max_field_length, :method, :name, :options
169
155
 
170
- # method is a string
171
156
  def initialize(data, method, options = {})
172
157
  self.method = method
173
158
  self.options = options || {} # could have been passed an explicit nil
@@ -231,7 +216,7 @@ class TablePrint
231
216
 
232
217
  # TODO: probably a cool array method to do this
233
218
  # finally - update the stack with the object(s) we found
234
- wrap(new_stack_objects).reverse_each do |stack_obj|
219
+ Array(new_stack_objects).reverse_each do |stack_obj|
235
220
  stack.unshift [stack_obj, new_method_chain]
236
221
  end
237
222
  end
@@ -266,18 +251,6 @@ class TablePrint
266
251
 
267
252
  private
268
253
 
269
- # borrowed from rails
270
- # turn objects into an array
271
- def wrap(object)
272
- if object.nil?
273
- []
274
- elsif object.respond_to?(:to_ary)
275
- object.to_ary
276
- else
277
- [object]
278
- end
279
- end
280
-
281
254
  # cut off field_value based on our previously determined width
282
255
  def truncate(field_value)
283
256
  copy = String.new(field_value)
@@ -309,7 +282,7 @@ class TablePrint
309
282
  return if data.nil?
310
283
  return if self.field_length >= self.max_field_length
311
284
 
312
- wrap(data).each do |data_obj|
285
+ Array(data).each do |data_obj|
313
286
  next_method = method.split(".").first
314
287
 
315
288
  return unless data_obj.respond_to? next_method
@@ -338,7 +311,7 @@ module Kernel
338
311
  def tp(data, options = {})
339
312
  start = Time.now
340
313
  table_print = TablePrint.new
341
- puts table_print.tp(data, options)
314
+ puts table_print.tp(Array(data), options)
342
315
  Time.now - start # we have to return *something*, might as well be execution time.
343
316
  end
344
317
 
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{table_print}
8
- s.version = "0.2.1"
7
+ s.name = "table_print"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chris Doyle"]
12
- s.date = %q{2011-06-23}
13
- s.description = %q{TablePrint formats an object or array of objects into columns for easy reading. To do this, it assumes the objects in your array all respond to the same methods (vs pretty_print or awesome_print, who can't create columns because your objects could be entirely different).}
14
- s.email = %q{archslide@gmail.com}
12
+ s.date = "2011-09-22"
13
+ s.description = "TablePrint formats an object or array of objects into columns for easy reading. To do this, it assumes the objects in your array all respond to the same methods (vs pretty_print or awesome_print, who can't create columns because your objects could be entirely different)."
14
+ s.email = "archslide@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -30,11 +30,11 @@ Gem::Specification.new do |s|
30
30
  "test/test_column.rb",
31
31
  "test/test_table_print.rb"
32
32
  ]
33
- s.homepage = %q{http://github.com/arches/table_print}
33
+ s.homepage = "http://github.com/arches/table_print"
34
34
  s.licenses = ["MIT"]
35
35
  s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.5.2}
37
- s.summary = %q{Turn objects into nicely formatted columns for easy reading}
36
+ s.rubygems_version = "1.8.10"
37
+ s.summary = "Turn objects into nicely formatted columns for easy reading"
38
38
  s.test_files = [
39
39
  "test/helper.rb",
40
40
  "test/test_column.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_print
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Doyle
@@ -15,12 +15,9 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-23 00:00:00 -07:00
19
- default_executable:
18
+ date: 2011-09-22 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- type: :development
24
21
  requirement: &id001 !ruby/object:Gem::Requirement
25
22
  none: false
26
23
  requirements:
@@ -30,11 +27,11 @@ dependencies:
30
27
  segments:
31
28
  - 0
32
29
  version: "0"
33
- name: shoulda
34
30
  version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
31
+ name: shoulda
36
32
  prerelease: false
37
33
  type: :development
34
+ - !ruby/object:Gem::Dependency
38
35
  requirement: &id002 !ruby/object:Gem::Requirement
39
36
  none: false
40
37
  requirements:
@@ -46,11 +43,11 @@ dependencies:
46
43
  - 0
47
44
  - 0
48
45
  version: 1.0.0
49
- name: bundler
50
46
  version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
47
+ name: bundler
52
48
  prerelease: false
53
49
  type: :development
50
+ - !ruby/object:Gem::Dependency
54
51
  requirement: &id003 !ruby/object:Gem::Requirement
55
52
  none: false
56
53
  requirements:
@@ -62,11 +59,11 @@ dependencies:
62
59
  - 5
63
60
  - 2
64
61
  version: 1.5.2
65
- name: jeweler
66
62
  version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
63
+ name: jeweler
68
64
  prerelease: false
69
65
  type: :development
66
+ - !ruby/object:Gem::Dependency
70
67
  requirement: &id004 !ruby/object:Gem::Requirement
71
68
  none: false
72
69
  requirements:
@@ -76,8 +73,10 @@ dependencies:
76
73
  segments:
77
74
  - 0
78
75
  version: "0"
79
- name: rcov
80
76
  version_requirements: *id004
77
+ name: rcov
78
+ prerelease: false
79
+ type: :development
81
80
  description: TablePrint formats an object or array of objects into columns for easy reading. To do this, it assumes the objects in your array all respond to the same methods (vs pretty_print or awesome_print, who can't create columns because your objects could be entirely different).
82
81
  email: archslide@gmail.com
83
82
  executables: []
@@ -100,7 +99,6 @@ files:
100
99
  - test/helper.rb
101
100
  - test/test_column.rb
102
101
  - test/test_table_print.rb
103
- has_rdoc: true
104
102
  homepage: http://github.com/arches/table_print
105
103
  licenses:
106
104
  - MIT
@@ -130,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
128
  requirements: []
131
129
 
132
130
  rubyforge_project:
133
- rubygems_version: 1.5.2
131
+ rubygems_version: 1.8.10
134
132
  signing_key:
135
133
  specification_version: 3
136
134
  summary: Turn objects into nicely formatted columns for easy reading