table_format 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/0120_default_options.rb +2 -0
- data/examples/0140_markdown_format.rb +1 -3
- data/examples/0180_object_spec.rb +61 -0
- data/lib/table_format/core_ext.rb +8 -2
- data/lib/table_format/version.rb +1 -1
- data/spec/object_spec.rb +69 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94481d8db1ce663a1d86a8b92d43d29e45992f2fd9afd7152e744b110c1e823d
|
4
|
+
data.tar.gz: cb027fdf6cc09d6881acfc32185532812de50f78cda8f443de7cee231fef49c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 024e3f0118c12b8b7378a84cf496ab3029715e7bd22b084f6e71aeacb7f5ace11a2ab63c3c43580a01b7faf1261de3bbd06c00c569c4a6223cc233517e16d67e
|
7
|
+
data.tar.gz: 6df8c7bb4cfdba147cac365776b73ba9943576912ef7a115125d95a47098a99888c215312088081b6e51c7b96469deb871644d3c5069e4c8b1b4082e639a3e3e
|
@@ -19,6 +19,7 @@ tp TableFormat.default_options
|
|
19
19
|
# >> | intersection_both | | |
|
20
20
|
# >> | horizon | - |
|
21
21
|
# >> | padding | |
|
22
|
+
# >> | truncate | 256 |
|
22
23
|
# >> | in_code | UTF-8 |
|
23
24
|
# >> |-------------------+-------|
|
24
25
|
# >> +-------------------+-------+
|
@@ -30,5 +31,6 @@ tp TableFormat.default_options
|
|
30
31
|
# >> | intersection_both | + |
|
31
32
|
# >> | horizon | - |
|
32
33
|
# >> | padding | |
|
34
|
+
# >> | truncate | 256 |
|
33
35
|
# >> | in_code | UTF-8 |
|
34
36
|
# >> +-------------------+-------+
|
@@ -31,12 +31,10 @@ puts
|
|
31
31
|
# set global options
|
32
32
|
TableFormat.default_options.update(markdown: true)
|
33
33
|
tp array
|
34
|
-
# >> |----+-------|
|
35
34
|
# >> | id | name |
|
36
|
-
# >>
|
35
|
+
# >> |----|-------|
|
37
36
|
# >> | 1 | alice |
|
38
37
|
# >> | 2 | bob |
|
39
|
-
# >> |----+-------|
|
40
38
|
# >>
|
41
39
|
# >> | id | name |
|
42
40
|
# >> |----|-------|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
$LOAD_PATH << '../lib'
|
2
|
+
require 'table_format'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
class C1
|
6
|
+
extend Enumerable
|
7
|
+
def self.each(&block)
|
8
|
+
[:a, :b].each(&block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class C2
|
13
|
+
extend Enumerable
|
14
|
+
def self.each(&block)
|
15
|
+
[[:a, :b]].each(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class C3
|
20
|
+
extend Enumerable
|
21
|
+
def self.each(&block)
|
22
|
+
[
|
23
|
+
{id: 1},
|
24
|
+
{id: 2},
|
25
|
+
].each(&block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class C4
|
30
|
+
extend Enumerable
|
31
|
+
def self.each(&block)
|
32
|
+
[
|
33
|
+
OpenStruct.new(attributes: {id: 1}),
|
34
|
+
OpenStruct.new(attributes: {id: 2}),
|
35
|
+
].each(&block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
OpenStruct.new(attributes: {id: 1}).respond_to?(:attributes) # => true
|
40
|
+
|
41
|
+
tp C1
|
42
|
+
tp C2
|
43
|
+
tp C3
|
44
|
+
tp C4
|
45
|
+
# >> |---|
|
46
|
+
# >> | a |
|
47
|
+
# >> | b |
|
48
|
+
# >> |---|
|
49
|
+
# >> |----------|
|
50
|
+
# >> | [:a, :b] |
|
51
|
+
# >> |----------|
|
52
|
+
# >> |----|
|
53
|
+
# >> | id |
|
54
|
+
# >> |----|
|
55
|
+
# >> | 1 |
|
56
|
+
# >> | 2 |
|
57
|
+
# >> |----|
|
58
|
+
# >> |-----------------------------------|
|
59
|
+
# >> | #<OpenStruct attributes={:id=>1}> |
|
60
|
+
# >> | #<OpenStruct attributes={:id=>2}> |
|
61
|
+
# >> |-----------------------------------|
|
@@ -23,10 +23,16 @@ end
|
|
23
23
|
Object.class_eval do
|
24
24
|
def to_t(**options)
|
25
25
|
case
|
26
|
-
when respond_to?(:to_h)
|
27
|
-
to_h.to_t(options)
|
28
26
|
when respond_to?(:to_a)
|
27
|
+
if false
|
28
|
+
if to_a.first.respond_to?(:attributes)
|
29
|
+
return to_a.collect(&:attributes).to_t(options)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
29
33
|
to_a.to_t(options)
|
34
|
+
when respond_to?(:to_h)
|
35
|
+
to_h.to_t(options)
|
30
36
|
else
|
31
37
|
TableFormat.generate([{self.class.name => self}], {header: false}.merge(options))
|
32
38
|
end
|
data/lib/table_format/version.rb
CHANGED
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
require "ostruct"
|
3
|
+
|
4
|
+
describe TableFormat do
|
5
|
+
class C1
|
6
|
+
extend Enumerable
|
7
|
+
def self.each(&block)
|
8
|
+
[:a, :b].each(&block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class C2
|
13
|
+
extend Enumerable
|
14
|
+
def self.each(&block)
|
15
|
+
[[:a, :b]].each(&block)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class C3
|
20
|
+
extend Enumerable
|
21
|
+
def self.each(&block)
|
22
|
+
[
|
23
|
+
{id: 1},
|
24
|
+
{id: 2},
|
25
|
+
].each(&block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class C4
|
30
|
+
extend Enumerable
|
31
|
+
def self.each(&block)
|
32
|
+
[
|
33
|
+
OpenStruct.new(attributes: {id: 1}),
|
34
|
+
OpenStruct.new(attributes: {id: 2}),
|
35
|
+
].each(&block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it do
|
40
|
+
C1.to_t.should == <<~EOT
|
41
|
+
|---|
|
42
|
+
| a |
|
43
|
+
| b |
|
44
|
+
|---|
|
45
|
+
EOT
|
46
|
+
|
47
|
+
C2.to_t.should == <<~EOT
|
48
|
+
|----------|
|
49
|
+
| [:a, :b] |
|
50
|
+
|----------|
|
51
|
+
EOT
|
52
|
+
|
53
|
+
C3.to_t.should == <<~EOT
|
54
|
+
|----|
|
55
|
+
| id |
|
56
|
+
|----|
|
57
|
+
| 1 |
|
58
|
+
| 2 |
|
59
|
+
|----|
|
60
|
+
EOT
|
61
|
+
|
62
|
+
C4.to_t.should == <<~EOT
|
63
|
+
|-----------------------------------|
|
64
|
+
| #<OpenStruct attributes={:id=>1}> |
|
65
|
+
| #<OpenStruct attributes={:id=>2}> |
|
66
|
+
|-----------------------------------|
|
67
|
+
EOT
|
68
|
+
end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akicho8
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- examples/0150_line_break.rb
|
114
114
|
- examples/0160_truncate.rb
|
115
115
|
- examples/0170_emoji.rb
|
116
|
+
- examples/0180_object_spec.rb
|
116
117
|
- lib/table_format.rb
|
117
118
|
- lib/table_format/core_ext.rb
|
118
119
|
- lib/table_format/generator.rb
|
@@ -120,6 +121,7 @@ files:
|
|
120
121
|
- lib/table_format/version.rb
|
121
122
|
- spec/active_record_spec.rb
|
122
123
|
- spec/core_ext_spec.rb
|
124
|
+
- spec/object_spec.rb
|
123
125
|
- spec/spec_helper.rb
|
124
126
|
- spec/table_format_spec.rb
|
125
127
|
- table_format.gemspec
|
@@ -153,5 +155,6 @@ summary: TableFormat shows text table like emacs org-table for easy reading.
|
|
153
155
|
test_files:
|
154
156
|
- spec/active_record_spec.rb
|
155
157
|
- spec/core_ext_spec.rb
|
158
|
+
- spec/object_spec.rb
|
156
159
|
- spec/spec_helper.rb
|
157
160
|
- spec/table_format_spec.rb
|