org_tp 0.0.10 → 0.0.11
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 +4 -4
- data/examples/0100_basic.rb +5 -1
- data/examples/0110_active_record.rb +3 -3
- data/lib/org_tp/core_ext.rb +3 -0
- data/lib/org_tp/generator.rb +15 -7
- data/lib/org_tp/version.rb +1 -1
- data/lib/org_tp.rb +2 -0
- data/spec/active_record_spec.rb +1 -1
- data/spec/core_ext_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e234454b6b0fd9d56f42dd6a0d768790334ab34
|
4
|
+
data.tar.gz: 49d4c34b17d000c9011890f46bf45f7f3af0d651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 819710ed0d778e6523ee7941bb020967002141a5a84fe6f7430cd17e1cc7bc98e1f8a2746e897e74d68683df592471cf404bde37cfc672f3ec29fcd69e3fd295
|
7
|
+
data.tar.gz: 42d9afde6a537e26f126a5dd0754a1953f95c77e3bb61d28927b392510bf0daa6ffee095fcace6ed95134971a859685df85896441081b283aade58f880452161
|
data/examples/0100_basic.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$LOAD_PATH << '../lib'
|
2
2
|
require 'org_tp'
|
3
3
|
|
4
|
+
pt 1
|
4
5
|
tp 1
|
5
6
|
tp 'foo'
|
6
7
|
tp :foo
|
@@ -13,6 +14,9 @@ puts [{'a': {'a': 1}}].to_t
|
|
13
14
|
# >> |---|
|
14
15
|
# >> | 1 |
|
15
16
|
# >> |---|
|
17
|
+
# >> |---|
|
18
|
+
# >> | 1 |
|
19
|
+
# >> |---|
|
16
20
|
# >> |-----|
|
17
21
|
# >> | foo |
|
18
22
|
# >> |-----|
|
@@ -24,7 +28,7 @@ puts [{'a': {'a': 1}}].to_t
|
|
24
28
|
# >> | bob |
|
25
29
|
# >> |-------|
|
26
30
|
# >> |------+-------|
|
27
|
-
# >> |
|
31
|
+
# >> | id | 1 |
|
28
32
|
# >> | name | alice |
|
29
33
|
# >> |------+-------|
|
30
34
|
# >> |----+-------|
|
@@ -20,7 +20,7 @@ tp User.first
|
|
20
20
|
tp User.limit(1)
|
21
21
|
tp ActiveRecord::Base.connection.select_all('SELECT * FROM users')
|
22
22
|
tp ActiveRecord::Base.connection.select_one('SELECT * FROM users')
|
23
|
-
tp ActiveRecord::Base.connection.select_value('SELECT 1 + 2')
|
23
|
+
tp ActiveRecord::Base.connection.select_value('SELECT 1 + 2') # !> `*' interpreted as argument prefix
|
24
24
|
# >> |----+-------|
|
25
25
|
# >> | id | name |
|
26
26
|
# >> |----+-------|
|
@@ -29,7 +29,7 @@ tp ActiveRecord::Base.connection.select_value('SELECT 1 + 2')
|
|
29
29
|
# >> | 3 | carol |
|
30
30
|
# >> |----+-------|
|
31
31
|
# >> |------+-------|
|
32
|
-
# >> |
|
32
|
+
# >> | id | 1 |
|
33
33
|
# >> | name | alice |
|
34
34
|
# >> |------+-------|
|
35
35
|
# >> |----+-------|
|
@@ -45,7 +45,7 @@ tp ActiveRecord::Base.connection.select_value('SELECT 1 + 2')
|
|
45
45
|
# >> | 3 | carol |
|
46
46
|
# >> |----+-------|
|
47
47
|
# >> |------+-------|
|
48
|
-
# >> |
|
48
|
+
# >> | id | 1 |
|
49
49
|
# >> | name | alice |
|
50
50
|
# >> |------+-------|
|
51
51
|
# >> |---|
|
data/lib/org_tp/core_ext.rb
CHANGED
data/lib/org_tp/generator.rb
CHANGED
@@ -51,6 +51,7 @@ module OrgTp
|
|
51
51
|
if @options[:header].nil?
|
52
52
|
@options[:header] = e[:header]
|
53
53
|
end
|
54
|
+
@options[:align] ||= e[:align]
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
@@ -74,11 +75,14 @@ module OrgTp
|
|
74
75
|
private
|
75
76
|
|
76
77
|
def table_rows_build
|
77
|
-
columns = @rows.inject([]) { |a, e| a | e.keys }
|
78
78
|
if @options[:header]
|
79
|
-
@column_names =
|
79
|
+
@column_names = all_columns
|
80
80
|
end
|
81
|
-
@table_rows = @rows.collect { |e| e.values_at(*
|
81
|
+
@table_rows = @rows.collect { |e| e.values_at(*all_columns) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def all_columns
|
85
|
+
@all_columns ||= @rows.inject([]) { |a, e| a | e.keys }
|
82
86
|
end
|
83
87
|
|
84
88
|
def column_widths
|
@@ -109,7 +113,7 @@ module OrgTp
|
|
109
113
|
|
110
114
|
def line_str(row)
|
111
115
|
s = row.collect.with_index {|e, i|
|
112
|
-
padding + just(e,
|
116
|
+
padding + just(e, i) + padding
|
113
117
|
}
|
114
118
|
s = s.join(@options[:vertical])
|
115
119
|
[@options[:vertical], s, @options[:vertical]].join
|
@@ -119,9 +123,11 @@ module OrgTp
|
|
119
123
|
@options[:padding]
|
120
124
|
end
|
121
125
|
|
122
|
-
def just(value,
|
123
|
-
align =
|
124
|
-
|
126
|
+
def just(value, i)
|
127
|
+
align = (@options[:align] || {}).fetch(all_columns[i]) do
|
128
|
+
Float(value) && :right rescue :left
|
129
|
+
end
|
130
|
+
space = ' ' * (column_widths[i] - str_width(value))
|
125
131
|
lspace = ''
|
126
132
|
rspace = ''
|
127
133
|
if align == :right
|
@@ -150,6 +156,7 @@ module OrgTp
|
|
150
156
|
{'(key)' => k.to_s, '(value)' => v.to_s}
|
151
157
|
end
|
152
158
|
},
|
159
|
+
align: {'(key)' => :right, '(value)' => :left},
|
153
160
|
},
|
154
161
|
|
155
162
|
# Array of Hash
|
@@ -201,6 +208,7 @@ if $0 == __FILE__
|
|
201
208
|
print OrgTp.generate({a: 1, b: 2}, header: false)
|
202
209
|
print OrgTp.generate([["a", "b"], ["c", "d"]])
|
203
210
|
print OrgTp.generate([["a", "b"], {"c" => "d"}])
|
211
|
+
print OrgTp.generate({id: 1, created_at: "2000-01-01"})
|
204
212
|
end
|
205
213
|
# >> |---+----|
|
206
214
|
# >> | a | [] |
|
data/lib/org_tp/version.rb
CHANGED
data/lib/org_tp.rb
CHANGED
data/spec/active_record_spec.rb
CHANGED
data/spec/core_ext_spec.rb
CHANGED
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.11
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|