org_tp 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24a89757969e7d697fd02316826d970741ca7e86
4
- data.tar.gz: b3defd4248ab8857dee375c8bbe9292ba0710962
3
+ metadata.gz: 1e234454b6b0fd9d56f42dd6a0d768790334ab34
4
+ data.tar.gz: 49d4c34b17d000c9011890f46bf45f7f3af0d651
5
5
  SHA512:
6
- metadata.gz: 8bd700c2a93cf23059da0a34cead03da4d94635e397ae395e81e167f32e48be163c0f750a2fd274843ea47b952d2513df8d2dab9bff6242dec42c6ad59d707f4
7
- data.tar.gz: 1d3ca465fd0aa29815399d37295ecda1ac23063b030d144c80e6aa87f07a636bc93858888cd24519d36c46d57ffe9b75f16ffb50378a3a2ffde76c9220ec2998
6
+ metadata.gz: 819710ed0d778e6523ee7941bb020967002141a5a84fe6f7430cd17e1cc7bc98e1f8a2746e897e74d68683df592471cf404bde37cfc672f3ec29fcd69e3fd295
7
+ data.tar.gz: 42d9afde6a537e26f126a5dd0754a1953f95c77e3bb61d28927b392510bf0daa6ffee095fcace6ed95134971a859685df85896441081b283aade58f880452161
@@ -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
- # >> | id | 1 |
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
- # >> | id | 1 |
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
- # >> | id | 1 |
48
+ # >> | id | 1 |
49
49
  # >> | name | alice |
50
50
  # >> |------+-------|
51
51
  # >> |---|
@@ -32,6 +32,9 @@ Kernel.class_eval do
32
32
  end
33
33
  end
34
34
  end
35
+
36
+ alias pt tp
37
+ alias tt tp
35
38
  end
36
39
 
37
40
  Array.class_eval do
@@ -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 = columns
79
+ @column_names = all_columns
80
80
  end
81
- @table_rows = @rows.collect { |e| e.values_at(*columns) }
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, column_widths[i]) + padding
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, max_width)
123
- align = Float(value) && :right rescue :left
124
- space = ' ' * (max_width - str_width(value))
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 | [] |
@@ -1,3 +1,3 @@
1
1
  module OrgTp
2
- VERSION = '0.0.10'
2
+ VERSION = '0.0.11'
3
3
  end
data/lib/org_tp.rb CHANGED
@@ -25,6 +25,8 @@ if defined?(Tapp)
25
25
  end
26
26
 
27
27
  register :tp, Tp
28
+ register :pt, Tp
29
+ register :tt, Tp
28
30
  end
29
31
 
30
32
  # # When tapp defaults to tp
@@ -30,7 +30,7 @@ describe OrgTp::ActiveRecord do
30
30
  EOT
31
31
  User.first.to_t.should == <<~EOT
32
32
  |------+---|
33
- | id | 1 |
33
+ | id | 1 |
34
34
  | name | 0 |
35
35
  |------+---|
36
36
  EOT
@@ -15,6 +15,6 @@ describe OrgTp do
15
15
 
16
16
  it 'result is like p method' do
17
17
  v = Object.new
18
- quietly { tp v }.should == v
18
+ quietly { pt v }.should == v
19
19
  end
20
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.10
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-16 00:00:00.000000000 Z
11
+ date: 2017-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport