org_tp 0.0.6 → 0.0.7

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: 1a86d8ba338efcb40e6028d7f44aaf3566c78698
4
- data.tar.gz: db53b23f2bc3f6368e633aff05ff7b289e3adb64
3
+ metadata.gz: 703ec54e13e94b547bfb120fbd9a5876fee1269e
4
+ data.tar.gz: 2b7498e7f7a6d9a2dbbd9c58d86bd5c1fa75250d
5
5
  SHA512:
6
- metadata.gz: d416f1a7625484a816e546f22107b3ab683b3df75510ec009d9d2bccd8afedb9cb94fbba9273ba96f51a413e936291988111ef4fe99e640a353b6b0fd75b08dc
7
- data.tar.gz: a05a86c3cb9fbf63cfa746b87e5133e19060239eb9ff609a1f298b83b3da14a41affa2ad2e96dfc4d574b85ae8cf46dc2dc62d3b2d4a1718e93aa1f87f034e56
6
+ metadata.gz: ac82e9d5fd8f682012dde62fad80ba29a0d4e5ffa95756176fe6a8bc08cbff1c472c11333d6ff22e08abb7df4e4abf760ac1249e618ff63404d8a9aac7b35898
7
+ data.tar.gz: 3fd8f1268341e40bc8a1aaa9bf10bf2c4416fdf55ad6ea1408d29a87d4a0b6f2362052c77b5188a3858499f75a4c8500071a8aa9c2275e3974f4c7d42a073539
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4
4
+ - jruby
data/README.org CHANGED
@@ -6,13 +6,13 @@
6
6
 
7
7
  Install as a standalone gem
8
8
 
9
- #+BEGIN_SRC shell
9
+ #+BEGIN_SRC shell-script
10
10
  $ gem install org_tp
11
11
  #+END_SRC
12
12
 
13
13
  Or install within application using Gemfile
14
14
 
15
- #+BEGIN_SRC shell
15
+ #+BEGIN_SRC shell-script
16
16
  $ bundle add org_tp
17
17
  $ bundle install
18
18
  #+END_SRC
@@ -77,7 +77,7 @@ tp :foo
77
77
  *** ActiveRecord or Mongoid
78
78
 
79
79
  #+BEGIN_SRC ruby
80
- ['alice', 'bob'].each {|e| User.create!(name: e) }
80
+ ['alice', 'bob'].each { |e| User.create!(name: e) }
81
81
  #+END_SRC
82
82
 
83
83
  #+BEGIN_SRC ruby
@@ -121,6 +121,8 @@ tp ActiveRecord::Base.connection.select_all('SELECT * FROM users')
121
121
 
122
122
  ** How to table as string
123
123
 
124
+ Use to_t method.
125
+
124
126
  #+BEGIN_SRC ruby
125
127
  puts [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}].to_t
126
128
  # >> |----+-------|
@@ -133,6 +135,8 @@ puts [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}].to_t
133
135
 
134
136
  ** Options
135
137
 
138
+ Pass as the second argument to tp or the first argument to to_t.
139
+
136
140
  #+BEGIN_SRC ruby
137
141
  tp 1
138
142
  # >> |---|
@@ -145,6 +149,16 @@ tp 1, intersection_both: '+'
145
149
  # >> +---+
146
150
  #+END_SRC
147
151
 
152
+ *** Markdown format example
153
+
154
+ #+BEGIN_SRC ruby
155
+ tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}], intersection: '|', cover: false
156
+ # >> | id | name |
157
+ # >> |----|-------|
158
+ # >> | 1 | alice |
159
+ # >> | 2 | bob |
160
+ #+END_SRC
161
+
148
162
  ** Global Options
149
163
 
150
164
  #+BEGIN_SRC ruby
@@ -172,7 +186,7 @@ tp 1
172
186
  # >> +---+
173
187
  #+END_SRC
174
188
 
175
- ** When used in conjunction with Tapp
189
+ ** When used in conjunction with tapp gem
176
190
 
177
191
  #+BEGIN_SRC ruby
178
192
  require 'tapp'
@@ -8,8 +8,8 @@ tp [:alice, :bob]
8
8
  tp({id: 1, name: 'alice'})
9
9
  tp [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}]
10
10
  puts [{id: 1, name: 'alice'}, {id: 2, name: 'bob'}].to_t
11
- puts [{'a' => ['a']}].to_t
12
- puts [{'a' => {'a' => 1}}].to_t
11
+ puts [{'a': ['a']}].to_t
12
+ puts [{'a': {'a': 1}}].to_t
13
13
  # >> |---|
14
14
  # >> | 1 |
15
15
  # >> |---|
@@ -42,10 +42,10 @@ puts [{'a' => {'a' => 1}}].to_t
42
42
  # >> |-------|
43
43
  # >> | a |
44
44
  # >> |-------|
45
- # >> | ['a'] |
45
+ # >> | ["a"] |
46
46
  # >> |-------|
47
- # >> |----------|
48
- # >> | a |
49
- # >> |----------|
50
- # >> | {'a'=>1} |
51
- # >> |----------|
47
+ # >> |---------|
48
+ # >> | a |
49
+ # >> |---------|
50
+ # >> | {:a=>1} |
51
+ # >> |---------|
@@ -2,8 +2,6 @@ $LOAD_PATH << '../lib'
2
2
  require 'active_record'
3
3
  require 'org_tp'
4
4
 
5
- ActiveRecord::Base.include(OrgTp::ActiveRecord)
6
-
7
5
  ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
8
6
  ActiveRecord::Migration.verbose = false
9
7
  ActiveRecord::Schema.define do
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH << '../lib'
2
+ require 'org_tp'
3
+
4
+ array = [
5
+ {id: 1, name: 'alice' },
6
+ {id: 2, name: 'bob' },
7
+ ]
8
+
9
+ # tp with options
10
+ tp array, intersection: '|', cover: false
11
+
12
+ # to_t with options
13
+ array.to_t(intersection: '|', cover: false) # => "| id | name |\n|----|-------|\n| 1 | alice |\n| 2 | bob |\n"
14
+
15
+ puts
16
+
17
+ # set global options
18
+ OrgTp::Generator.default_options.update(intersection: '|', cover: false)
19
+ tp array
20
+ # >> | id | name |
21
+ # >> |----|-------|
22
+ # >> | 1 | alice |
23
+ # >> | 2 | bob |
24
+ # >>
25
+ # >> | id | name |
26
+ # >> |----|-------|
27
+ # >> | 1 | alice |
28
+ # >> | 2 | bob |
@@ -12,6 +12,7 @@ module OrgTp
12
12
  class_attribute :default_options
13
13
  self.default_options = {
14
14
  header: nil,
15
+ cover: true,
15
16
  vertical: '|',
16
17
  intersection: '+',
17
18
  intersection_both: '|',
@@ -43,13 +44,17 @@ module OrgTp
43
44
  table_rows_build
44
45
 
45
46
  out = []
46
- out << separater
47
+ if @options[:cover]
48
+ out << separater
49
+ end
47
50
  if @column_names
48
51
  out << header
49
52
  out << separater
50
53
  end
51
54
  out << body
52
- out << separater
55
+ if @options[:cover]
56
+ out << separater
57
+ end
53
58
  out.flatten * "\n" + "\n"
54
59
  end
55
60
 
@@ -1,3 +1,3 @@
1
1
  module OrgTp
2
- VERSION = '0.0.6'
2
+ VERSION = '0.0.7'
3
3
  end
data/lib/org_tp.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'org_tp/version'
2
- require 'org_tp/org_tp'
2
+ require 'org_tp/generator'
3
3
  require 'org_tp/core_ext'
4
4
 
5
5
  if defined?(Rails)
@@ -2,7 +2,7 @@ require_relative 'spec_helper'
2
2
  require 'active_record'
3
3
 
4
4
  ActiveRecord::Base.send(:include, OrgTp::ActiveRecord)
5
- ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
5
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
6
6
  ActiveRecord::Migration.verbose = false
7
7
 
8
8
  ActiveRecord::Schema.define do
data/spec/org_tp_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe OrgTp do
13
13
  OrgTp.generate([]).should == ''
14
14
  end
15
15
 
16
- it 'フォーマット指定なし' do
16
+ it 'default' do
17
17
  OrgTp.generate(@rows).should == <<~EOT
18
18
  |----+-------+-------------|
19
19
  | id | name | description |
@@ -47,6 +47,16 @@ EOT
47
47
  EOT
48
48
  end
49
49
 
50
+ it 'markdown format' do
51
+ OrgTp.generate(@rows, intersection: '|', cover: false).should == <<~EOT
52
+ | id | name | description |
53
+ |----|-------|-------------|
54
+ | 1 | alice | 0123456789 |
55
+ | 2 | bob | あいうえお |
56
+ | 3 | bob | |
57
+ EOT
58
+ end
59
+
50
60
  describe 'various to_t' do
51
61
  it 'hash array' do
52
62
  [{a: 1}].to_t.should == <<~EOT
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.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - akicho8
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-14 00:00:00.000000000 Z
11
+ date: 2017-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -101,6 +101,7 @@ extensions: []
101
101
  extra_rdoc_files: []
102
102
  files:
103
103
  - ".gitignore"
104
+ - ".travis.yml"
104
105
  - Gemfile
105
106
  - README.org
106
107
  - Rakefile
@@ -109,9 +110,10 @@ files:
109
110
  - examples/0120_default_options.rb
110
111
  - examples/0130_mongoid.rb
111
112
  - examples/0140_tapp.rb
113
+ - examples/0150_markdown_format.rb
112
114
  - lib/org_tp.rb
113
115
  - lib/org_tp/core_ext.rb
114
- - lib/org_tp/org_tp.rb
116
+ - lib/org_tp/generator.rb
115
117
  - lib/org_tp/railtie.rb
116
118
  - lib/org_tp/version.rb
117
119
  - org_tp.gemspec