table_print 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmZlY2QyNGI0MGRkYzExMjJhMDE1N2QwNjhkN2EzYjVkODVmNzE3OA==
4
+ ZTViMjhhZmQ0MTQ4MjAzOWE2YjY3YmQzYzMyMjNkMmNiYzI5MzFhZg==
5
5
  data.tar.gz: !binary |-
6
- MzBmY2MwYmY2MDFlMDE1NjcwYjg3NGJjNmEwN2ViMDdiOTgzZWYzYg==
6
+ M2U2ZGI4ZjA1OTUyOWY1YTY1OGVhY2Q4OWE5NWY3YWJhMWFiNTdkOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzcxYjFkMDBlOTZkMmZkYzljZDRkNzI2MmEwOGE4ZjBhY2NhZThjYjRmOWZm
10
- OTdmOGNiNjBjMzIwNmM0MzVkMmE0MTdjZTc4Mjc0ZGY4OGE5NWJlMWZjNGU3
11
- MmIzYTJmNjEzNmEwZDRjNjRlNGE5MGQxZWNhMWNlYzA1ODMyNjI=
9
+ NWRlZGRjZmY5ZWY1OWU0YzYxODdhNmJkMzAwZjdhOGU3MGY2MjhiY2UxZmY3
10
+ M2Q3OTVmZGMyZDI3MTE0NDJiZjNkZjkxNzM4MjFhMmIzNWIxYWE0NWYwZGY4
11
+ OGM3ZmU5MzliYmI1M2I2MTg1Y2YxMTcxOTk4ZmY3OTk4NjAxYzQ=
12
12
  data.tar.gz: !binary |-
13
- Nzg4YzdlNWM0MGRlNjc5ZDE4ZmMyODFlNTc4ZWI5ODhkZDAxYzIxMmUwYjI1
14
- MDZmY2EyNDU5YWVjMTYwZTZlODM3MGE2NWFlYTYwOWE0MjVlMjhhZDQ0MGVh
15
- M2MyMjgxNzUzZmJiZTJhMzU5NDhjZDcxNjQ1MGUyYzZkM2M3MDA=
13
+ Y2QzYTFiOWQ2ZmQyMTJjZDE3OWQ5ZDQyNzFhOTc2MjI1MjNkZmQ1ZGJhMGMx
14
+ ZTViYWRlNTI4MTNmMDYzMmYyMDU4OTE5ODQ2ZDRmMzM1Y2NjZDc5NTJiNzI0
15
+ NzU4OGE2MGQwYTM0ZjRlYjhlODBlYWIyZTU0OTFmYzNkZjdlZWM=
data/lib/table_print.rb CHANGED
@@ -17,7 +17,7 @@ module TablePrint
17
17
  end
18
18
 
19
19
  def initialize(data, options={})
20
- @data = [data].flatten.compact
20
+ @data = Array(data).compact
21
21
  @options = options
22
22
  @columns = nil
23
23
  @start_time = Time.now
@@ -70,6 +70,6 @@ end
70
70
 
71
71
  def tp(data=Class, *options)
72
72
  printer = TablePrint::Printer.new(data, options)
73
- puts printer.table_print unless data.is_a? Class
73
+ TablePrint::Config.io.puts printer.table_print unless data.is_a? Class
74
74
  TablePrint::Returnable.new(printer.message) # we have to return *something*, might as well be execution time.
75
75
  end
@@ -3,10 +3,12 @@ module TablePrint
3
3
 
4
4
  DEFAULT_MAX_WIDTH = 30
5
5
  DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
6
+ DEFAULT_IO = STDOUT
6
7
 
7
8
  @@max_width = DEFAULT_MAX_WIDTH
8
9
  @@time_format = DEFAULT_TIME_FORMAT
9
10
  @@multibyte = false
11
+ @@io = STDOUT
10
12
 
11
13
  @@klasses = {}
12
14
 
@@ -54,5 +56,14 @@ module TablePrint
54
56
  def self.time_format=(format)
55
57
  @@time_format = format
56
58
  end
59
+
60
+ def self.io
61
+ @@io
62
+ end
63
+
64
+ def self.io=(io)
65
+ raise StandardError.new("IO object must respond to :puts") unless io.respond_to? :puts
66
+ @@io = io
67
+ end
57
68
  end
58
69
  end
@@ -1,4 +1,4 @@
1
1
  module TablePrint
2
- VERSION = "1.5.1"
2
+ VERSION = "1.5.2"
3
3
  end
4
4
 
data/spec/config_spec.rb CHANGED
@@ -47,5 +47,31 @@ describe TablePrint::Config do
47
47
  end
48
48
  end
49
49
  end
50
+
51
+ describe "io" do
52
+ before :all do
53
+ Sandbox.add_class("MyIO")
54
+ Sandbox.add_method("MyIO", :puts) {}
55
+ end
56
+
57
+ it "accepts object that respond to puts" do
58
+ myIO = Sandbox::MyIO.new
59
+ TablePrint::Config.set(:io, [myIO])
60
+ TablePrint::Config.io.should == myIO
61
+ end
62
+
63
+ it "doesn't accept objects unless they respond to puts" do
64
+ lambda {
65
+ TablePrint::Config.set(:io, [""])
66
+ }.should raise_error StandardError
67
+ end
68
+
69
+ it "defaults to STDOUT" do
70
+ myIO = Sandbox::MyIO.new
71
+ TablePrint::Config.set(:io, [myIO])
72
+ TablePrint::Config.clear(:io)
73
+ TablePrint::Config.io.should == STDOUT
74
+ end
75
+ end
50
76
  end
51
77
 
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.1
4
+ version: 1.5.2
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-20 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cat