org_tp 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.org +9 -6
- data/examples/0120_default_options.rb +3 -3
- data/examples/0140_tapp.rb +7 -5
- data/examples/0150_markdown_format.rb +1 -1
- data/lib/org_tp/core_ext.rb +6 -4
- data/lib/org_tp/generator.rb +19 -13
- data/lib/org_tp/version.rb +1 -1
- data/lib/org_tp.rb +4 -0
- data/spec/core_ext_spec.rb +20 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e57f2468252f682a1338ee3683762c47bc6885c8
|
4
|
+
data.tar.gz: faa6355e08d36b09c233cdd9feb9d24fcac2a8c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf37326c8506fbb181552144cd87ec26eebf62078cf668fcc584a88c1b9aa098c12ef37a462e32a851102ab75d248a6e5858c5449779b6f5e9fe1ccd6617a940
|
7
|
+
data.tar.gz: 7992e2f0d622b37f9142a8bc7a4451e1b895b19d9402782d4c55f126a78c84852172ec832930a32dbc3095e48e2cc6756acfc5d030209f9c90085c78745e2f2a
|
data/README.org
CHANGED
@@ -162,7 +162,7 @@ tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}], intersection: '|', cover: fal
|
|
162
162
|
** Global Options
|
163
163
|
|
164
164
|
#+BEGIN_SRC ruby
|
165
|
-
tp OrgTp
|
165
|
+
tp OrgTp.default_options
|
166
166
|
# >> |-------------------+-------|
|
167
167
|
# >> | header | |
|
168
168
|
# >> | vertical | | |
|
@@ -178,7 +178,7 @@ tp 1
|
|
178
178
|
# >> | 1 |
|
179
179
|
# >> |---|
|
180
180
|
|
181
|
-
OrgTp
|
181
|
+
OrgTp.default_options[:intersection_both] = '+'
|
182
182
|
|
183
183
|
tp 1
|
184
184
|
# >> +---+
|
@@ -192,8 +192,11 @@ tp 1
|
|
192
192
|
require 'tapp'
|
193
193
|
require 'org_tp'
|
194
194
|
|
195
|
-
|
196
|
-
# >>
|
197
|
-
# >> |
|
198
|
-
# >>
|
195
|
+
"Hello".reverse.tapp.reverse.tapp
|
196
|
+
# >> |-------|
|
197
|
+
# >> | olleH |
|
198
|
+
# >> |-------|
|
199
|
+
# >> |-------|
|
200
|
+
# >> | Hello |
|
201
|
+
# >> |-------|
|
199
202
|
#+END_SRC
|
@@ -3,9 +3,9 @@ require 'org_tp'
|
|
3
3
|
|
4
4
|
tp 1, intersection_both: '+'
|
5
5
|
|
6
|
-
tp OrgTp
|
7
|
-
OrgTp
|
8
|
-
tp OrgTp
|
6
|
+
tp OrgTp.default_options
|
7
|
+
OrgTp.default_options.update(intersection_both: '+')
|
8
|
+
tp OrgTp.default_options
|
9
9
|
|
10
10
|
# >> +---+
|
11
11
|
# >> | 1 |
|
data/examples/0140_tapp.rb
CHANGED
@@ -2,8 +2,10 @@ $LOAD_PATH << '../lib'
|
|
2
2
|
require 'tapp'
|
3
3
|
require 'org_tp'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
# >>
|
8
|
-
# >>
|
9
|
-
# >>
|
5
|
+
"Hello".reverse.tapp.reverse.tapp
|
6
|
+
# >> |-------|
|
7
|
+
# >> | olleH |
|
8
|
+
# >> |-------|
|
9
|
+
# >> |-------|
|
10
|
+
# >> | Hello |
|
11
|
+
# >> |-------|
|
@@ -15,7 +15,7 @@ array.to_t(intersection: '|', cover: false) # => "| id | name |\n|----|-------|
|
|
15
15
|
puts
|
16
16
|
|
17
17
|
# set global options
|
18
|
-
OrgTp
|
18
|
+
OrgTp.default_options.update(intersection: '|', cover: false)
|
19
19
|
tp array
|
20
20
|
# >> | id | name |
|
21
21
|
# >> |----|-------|
|
data/lib/org_tp/core_ext.rb
CHANGED
@@ -18,10 +18,12 @@ Kernel.class_eval do
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def tp(object, **options)
|
21
|
-
|
22
|
-
object.to_t
|
23
|
-
|
24
|
-
|
21
|
+
object.tap do
|
22
|
+
if object.respond_to?(:to_t)
|
23
|
+
object.to_t(options).display
|
24
|
+
else
|
25
|
+
OrgTp.generate([{object.class.name => object}], {header: false}.merge(options)).display
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
29
|
end
|
data/lib/org_tp/generator.rb
CHANGED
@@ -4,13 +4,8 @@ require 'active_support/core_ext/class/attribute' # for class_attribute
|
|
4
4
|
require 'kconv'
|
5
5
|
|
6
6
|
module OrgTp
|
7
|
-
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
class Generator
|
12
|
-
class_attribute :default_options
|
13
|
-
self.default_options = {
|
7
|
+
mattr_accessor :default_options do
|
8
|
+
{
|
14
9
|
header: nil,
|
15
10
|
cover: true,
|
16
11
|
vertical: '|',
|
@@ -20,9 +15,20 @@ module OrgTp
|
|
20
15
|
padding: ' ',
|
21
16
|
in_code: Kconv::UTF8,
|
22
17
|
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.generate(*args, &block)
|
21
|
+
Generator.new(*args, &block).generate
|
22
|
+
end
|
23
|
+
|
24
|
+
class Generator
|
25
|
+
def self.default_options
|
26
|
+
warn "[DEPRECATED] `OrgTp::Generator.default_options' is deprecated. Use `OrgTp.default_options' instead."
|
27
|
+
OrgTp.default_options
|
28
|
+
end
|
23
29
|
|
24
30
|
def initialize(rows, **options)
|
25
|
-
@options = default_options.merge(options)
|
31
|
+
@options = OrgTp.default_options.merge(options)
|
26
32
|
@rows = rows
|
27
33
|
@column_names = nil
|
28
34
|
end
|
@@ -141,17 +147,17 @@ module OrgTp
|
|
141
147
|
|
142
148
|
# Array of Hash
|
143
149
|
{
|
144
|
-
_case: -> e { e.kind_of?(Array) && e.all? { |e| e.kind_of?(Hash) } },
|
150
|
+
_case: -> e { e.kind_of?(Array) && e.all? { |e| e.kind_of?(Hash) } },
|
145
151
|
header: true,
|
146
152
|
process: -> e { e },
|
147
153
|
},
|
148
154
|
|
149
155
|
# Array excluding Hash
|
150
156
|
{
|
151
|
-
_case: -> e { e.kind_of?(Array) && e.none? { |e| e.kind_of?(Hash) } },
|
157
|
+
_case: -> e { e.kind_of?(Array) && e.none? { |e| e.kind_of?(Hash) } },
|
152
158
|
header: false,
|
153
159
|
process: -> e {
|
154
|
-
e.collect do |e|
|
160
|
+
e.collect do |e|
|
155
161
|
{'(array_element)' => e}
|
156
162
|
end
|
157
163
|
},
|
@@ -159,10 +165,10 @@ module OrgTp
|
|
159
165
|
|
160
166
|
# Array containing Hash and others
|
161
167
|
{
|
162
|
-
_case: -> e { e.kind_of?(Array) && e.any? { |e| !e.kind_of?(Hash) } },
|
168
|
+
_case: -> e { e.kind_of?(Array) && e.any? { |e| !e.kind_of?(Hash) } },
|
163
169
|
header: true,
|
164
170
|
process: -> e {
|
165
|
-
e.collect do |e|
|
171
|
+
e.collect do |e|
|
166
172
|
if e.kind_of? Hash
|
167
173
|
e
|
168
174
|
else
|
data/lib/org_tp/version.rb
CHANGED
data/lib/org_tp.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe OrgTp do
|
4
|
+
require 'tempfile'
|
5
|
+
require 'active_support/testing/stream'
|
6
|
+
include ActiveSupport::Testing::Stream
|
7
|
+
|
8
|
+
it do
|
9
|
+
capture(:stdout) { tp 1 }.should == <<~EOT
|
10
|
+
|---|
|
11
|
+
| 1 |
|
12
|
+
|---|
|
13
|
+
EOT
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'result is like p method' do
|
17
|
+
v = Object.new
|
18
|
+
quietly { tp v }.should == v
|
19
|
+
end
|
20
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: org_tp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akicho8
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -118,6 +118,7 @@ files:
|
|
118
118
|
- lib/org_tp/version.rb
|
119
119
|
- org_tp.gemspec
|
120
120
|
- spec/active_record_spec.rb
|
121
|
+
- spec/core_ext_spec.rb
|
121
122
|
- spec/org_tp_spec.rb
|
122
123
|
- spec/spec_helper.rb
|
123
124
|
homepage: https://github.com/akicho8/org_tp
|
@@ -150,5 +151,6 @@ specification_version: 4
|
|
150
151
|
summary: OrgTp shows text table like emacs org-table for easy reading.
|
151
152
|
test_files:
|
152
153
|
- spec/active_record_spec.rb
|
154
|
+
- spec/core_ext_spec.rb
|
153
155
|
- spec/org_tp_spec.rb
|
154
156
|
- spec/spec_helper.rb
|