kosi 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +8 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.html +273 -0
- data/README.md +290 -0
- data/Rakefile +8 -0
- data/kosi.gemspec +28 -0
- data/lib/kosi.rb +13 -0
- data/lib/kosi/align.rb +33 -0
- data/lib/kosi/char_option.rb +17 -0
- data/lib/kosi/connector_char.rb +26 -0
- data/lib/kosi/header.rb +18 -0
- data/lib/kosi/horizontal_border_char.rb +26 -0
- data/lib/kosi/options.rb +15 -0
- data/lib/kosi/separate_each_row.rb +15 -0
- data/lib/kosi/validators.rb +3 -0
- data/lib/kosi/validators/each_array_length_validator.rb +21 -0
- data/lib/kosi/validators/row_type_validator.rb +19 -0
- data/lib/kosi/version.rb +4 -0
- data/lib/kosi/vertical_border_char.rb +26 -0
- data/lib/table.rb +138 -0
- data/spec/kosi/align_spec.rb +77 -0
- data/spec/kosi/connector_char_spec.rb +59 -0
- data/spec/kosi/header_spec.rb +93 -0
- data/spec/kosi/horizontal_border_char_spec.rb +59 -0
- data/spec/kosi/separate_each_row_spec.rb +55 -0
- data/spec/kosi/validators/each_array_length_validator_spec.rb +56 -0
- data/spec/kosi/validators/row_type_validator_spec.rb +51 -0
- data/spec/kosi/vertical_border_char_spec.rb +59 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/table_spec.rb +134 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b938040434b75078bdccb23b65954e2307d248d
|
4
|
+
data.tar.gz: 1acde4a7534f0279db675b1800fbbfd59bd405d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c9f8b2329f4d8ef714a28f74d763ae3b4b494dfbf7d232c53b01635fb90dd8f2e640aad0aa22d4ada7110ec8df820a35fa5bc321071da76a3c77d9731d71141c
|
7
|
+
data.tar.gz: c18678aa7bb8a88f09682659871615d87b591a17085d2ce074bf6a12a07ba6d7b0484bbc827c6a3c6eca7fa8052627b4b91c57b030331b626fc4a8039b4a988a
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
gem "rspec", "~> 2.14.1"
|
5
|
+
gem "thor", "~> 0.18.1"
|
6
|
+
gem "simplecov", "~> 0.8.2"
|
7
|
+
gem "activesupport", "~> 4.0.1"
|
8
|
+
gem "activemodel", "~> 4.0.2"
|
9
|
+
gem "tudu", "~> 0.0.4"
|
10
|
+
group :test do
|
11
|
+
gem 'coveralls', require: false
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 tbpgr
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.html
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html lang="ja">
|
3
|
+
<head>
|
4
|
+
<meta charset="UTF-8">
|
5
|
+
<title>Markdown Preview</title>
|
6
|
+
<link rel="stylesheet" href="C:\Users\tabei\AppData\Roaming\Sublime Text 2\Packages\User\markdown_template\styles\default.css">
|
7
|
+
<link rel="stylesheet" href="C:\Users\tabei\AppData\Roaming\Sublime Text 2\Packages\User\markdown_template\github.css">
|
8
|
+
<script src="C:\Users\tabei\AppData\Roaming\Sublime Text 2\Packages\User\markdown_template\highlight.pack.js"></script>
|
9
|
+
<script>hljs.initHighlightingOnLoad();</script>
|
10
|
+
</head>
|
11
|
+
<body>
|
12
|
+
<h1 id="kosi">Kosi</h1>
|
13
|
+
<p>ターミナル用表フォーマットサポートツール。格子。</p>
|
14
|
+
<h2 id="installation">Installation</h2>
|
15
|
+
<p>Add this line to your application's Gemfile:</p>
|
16
|
+
<pre><code>gem 'kosi'
|
17
|
+
</code></pre>
|
18
|
+
<p>And then execute:</p>
|
19
|
+
<pre><code>$ bundle
|
20
|
+
</code></pre>
|
21
|
+
<p>Or install it yourself as:</p>
|
22
|
+
<pre><code>$ gem install kosi
|
23
|
+
</code></pre>
|
24
|
+
<h2 id="description">Description</h2>
|
25
|
+
<p>2次元配列をテーブルフォーマットにして出力します。<br />
|
26
|
+
terminal-table gemの日本語対応版にあたります。<br />
|
27
|
+
(terminal-tableはASCII対応のみなので全角文字が混ざるとテーブルレイアウトが崩れる) </p>
|
28
|
+
<p>具体的には </p>
|
29
|
+
<ul>
|
30
|
+
<li>Unicode 1-127 => ASCII。1文字分として計算</li>
|
31
|
+
<li>Unicode 65_377(0xff61)..65_439(0xff9f) => 半角カナ。1文字分として計算</li>
|
32
|
+
<li>その他 => 全角として扱う。2文字分として計算</li>
|
33
|
+
</ul>
|
34
|
+
<h2 id="options">Options</h2>
|
35
|
+
<h3 id="align">Align</h3>
|
36
|
+
<p>配置指定。右寄せ、左寄せ、中央を選択可能。 </p>
|
37
|
+
<table>
|
38
|
+
<thead>
|
39
|
+
<tr>
|
40
|
+
<th align="left">設定可能パラメータ</th>
|
41
|
+
<th align="left">説明</th>
|
42
|
+
</tr>
|
43
|
+
</thead>
|
44
|
+
<tbody>
|
45
|
+
<tr>
|
46
|
+
<td align="left">Kosi::Align::TYPE::RIGHT</td>
|
47
|
+
<td align="left">右寄せ</td>
|
48
|
+
</tr>
|
49
|
+
<tr>
|
50
|
+
<td align="left">Kosi::Align::TYPE::LEFT</td>
|
51
|
+
<td align="left">左寄せ。デフォルト</td>
|
52
|
+
</tr>
|
53
|
+
<tr>
|
54
|
+
<td align="left">Kosi::Align::TYPE::CENTER</td>
|
55
|
+
<td align="left">中央</td>
|
56
|
+
</tr>
|
57
|
+
</tbody>
|
58
|
+
</table>
|
59
|
+
<h3 id="connectorchar">ConnectorChar</h3>
|
60
|
+
<p>表の結合部に表示するテキスト。1文字で指定。<br />
|
61
|
+
下記で言うところの 「+」がConnectorChar。 </p>
|
62
|
+
<pre><code>+-----+------+-------+
|
63
|
+
|a |b |c |
|
64
|
+
+-----+------+-------+
|
65
|
+
</code></pre>
|
66
|
+
|
67
|
+
<h3 id="header">Header</h3>
|
68
|
+
<p>表のヘッダー。配列で指定。<br />
|
69
|
+
デフォルトはヘッダーなし。 </p>
|
70
|
+
<h3 id="horizontalborderchar">HorizontalBorderChar</h3>
|
71
|
+
<p>水平線を1文字で設定。<br />
|
72
|
+
デフォルトは「-」 </p>
|
73
|
+
<h3 id="separateeachrow">SeparateEachRow</h3>
|
74
|
+
<p>各行に区切り線を入れるかどうか。<br />
|
75
|
+
デフォルトは「false」 </p>
|
76
|
+
<h3 id="verticalborderchar">VerticalBorderChar</h3>
|
77
|
+
<p>垂直線を1文字で設定。<br />
|
78
|
+
デフォルトは「|」 </p>
|
79
|
+
<h2 id="usage">Usage</h2>
|
80
|
+
<h3 id="オプション指定なし">オプション指定なし</h3>
|
81
|
+
<pre><code class="ruby">require 'kosi'
|
82
|
+
|
83
|
+
kosi = Kosi::Table.new
|
84
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
85
|
+
</code></pre>
|
86
|
+
|
87
|
+
<p>出力<br />
|
88
|
+
※GitHubの表示上ずれているかもしれませんが、等幅フォント利用時にそろいます。</p>
|
89
|
+
<pre><code>+-----+------+-------+
|
90
|
+
|a |b |c |
|
91
|
+
|ほゲ1|ひゲ22|へゲ333|
|
92
|
+
+-----+------+-------+
|
93
|
+
</code></pre>
|
94
|
+
|
95
|
+
<h3 id="align指定">Align指定</h3>
|
96
|
+
<pre><code class="ruby">require 'kosi'
|
97
|
+
|
98
|
+
kosi = Kosi::Table.new({align: Kosi::Align::TYPE::CENTER})
|
99
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
100
|
+
kosi = Kosi::Table.new({align: Kosi::Align::TYPE::RIGHT})
|
101
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
102
|
+
kosi = Kosi::Table.new({align: Kosi::Align::TYPE::LEFT})
|
103
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
104
|
+
</code></pre>
|
105
|
+
|
106
|
+
<p>出力 </p>
|
107
|
+
<pre><code>+-----+------+-------+
|
108
|
+
| a | b | c |
|
109
|
+
|ほゲ1|ひゲ22|へゲ333|
|
110
|
+
+-----+------+-------+
|
111
|
+
+-----+------+-------+
|
112
|
+
| a| b| c|
|
113
|
+
|ほゲ1|ひゲ22|へゲ333|
|
114
|
+
+-----+------+-------+
|
115
|
+
+-----+------+-------+
|
116
|
+
|a |b |c |
|
117
|
+
|ほゲ1|ひゲ22|へゲ333|
|
118
|
+
+-----+------+-------+
|
119
|
+
</code></pre>
|
120
|
+
|
121
|
+
<h3 id="connectorchar指定">ConnectorChar指定</h3>
|
122
|
+
<pre><code class="ruby">require 'kosi'
|
123
|
+
|
124
|
+
kosi = Kosi::Table.new
|
125
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
126
|
+
kosi = Kosi::Table.new({connector_char: 'x'})
|
127
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
128
|
+
kosi = Kosi::Table.new({connector_char: '$'})
|
129
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
130
|
+
</code></pre>
|
131
|
+
|
132
|
+
<p>出力 </p>
|
133
|
+
<pre><code>+-----+------+-------+
|
134
|
+
|a |b |c |
|
135
|
+
|ほゲ1|ひゲ22|へゲ333|
|
136
|
+
+-----+------+-------+
|
137
|
+
x-----x------x-------x
|
138
|
+
|a |b |c |
|
139
|
+
|ほゲ1|ひゲ22|へゲ333|
|
140
|
+
x-----x------x-------x
|
141
|
+
$-----$------$-------$
|
142
|
+
|a |b |c |
|
143
|
+
|ほゲ1|ひゲ22|へゲ333|
|
144
|
+
$-----$------$-------$
|
145
|
+
</code></pre>
|
146
|
+
|
147
|
+
<h3 id="header指定">Header指定</h3>
|
148
|
+
<pre><code class="ruby">require 'kosi'
|
149
|
+
|
150
|
+
kosi = Kosi::Table.new
|
151
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
152
|
+
kosi = Kosi::Table.new({header: %w{column1 column2 column3}})
|
153
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
154
|
+
</code></pre>
|
155
|
+
|
156
|
+
<p>出力 </p>
|
157
|
+
<pre><code>+-----+------+-------+
|
158
|
+
|a |b |c |
|
159
|
+
|ほゲ1|ひゲ22|へゲ333|
|
160
|
+
+-----+------+-------+
|
161
|
+
+-------+-------+-------+
|
162
|
+
|column1|column2|column3|
|
163
|
+
+-------+-------+-------+
|
164
|
+
|a |b |c |
|
165
|
+
|ほゲ1 |ひゲ22 |へゲ333|
|
166
|
+
+-------+-------+-------+
|
167
|
+
</code></pre>
|
168
|
+
|
169
|
+
<h3 id="horizontalborderchar指定">HorizontalBorderChar指定</h3>
|
170
|
+
<pre><code class="ruby">require 'kosi'
|
171
|
+
|
172
|
+
kosi = Kosi::Table.new
|
173
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
174
|
+
kosi = Kosi::Table.new({horizontal_border_char: '*'})
|
175
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
176
|
+
</code></pre>
|
177
|
+
|
178
|
+
<p>出力 </p>
|
179
|
+
<pre><code>+-----+------+-------+
|
180
|
+
|a |b |c |
|
181
|
+
|ほゲ1|ひゲ22|へゲ333|
|
182
|
+
+-----+------+-------+
|
183
|
+
+*****+******+*******+
|
184
|
+
|a |b |c |
|
185
|
+
|ほゲ1|ひゲ22|へゲ333|
|
186
|
+
+*****+******+*******+
|
187
|
+
</code></pre>
|
188
|
+
|
189
|
+
<h3 id="separateeachrow指定">SeparateEachRow指定</h3>
|
190
|
+
<pre><code class="ruby">require 'kosi'
|
191
|
+
|
192
|
+
kosi = Kosi::Table.new
|
193
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333'], [*'a'..'c']])
|
194
|
+
kosi = Kosi::Table.new({separate_each_row: true})
|
195
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333'], [*'a'..'c']])
|
196
|
+
</code></pre>
|
197
|
+
|
198
|
+
<p>出力 </p>
|
199
|
+
<pre><code>+-----+------+-------+
|
200
|
+
|a |b |c |
|
201
|
+
|ほゲ1|ひゲ22|へゲ333|
|
202
|
+
|a |b |c |
|
203
|
+
+-----+------+-------+
|
204
|
+
+-----+------+-------+
|
205
|
+
|a |b |c |
|
206
|
+
+-----+------+-------+
|
207
|
+
|ほゲ1|ひゲ22|へゲ333|
|
208
|
+
+-----+------+-------+
|
209
|
+
|a |b |c |
|
210
|
+
+-----+------+-------+
|
211
|
+
</code></pre>
|
212
|
+
|
213
|
+
<h3 id="verticalborderchar指定">VerticalBorderChar指定</h3>
|
214
|
+
<pre><code class="ruby">require 'kosi'
|
215
|
+
|
216
|
+
kosi = Kosi::Table.new
|
217
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
218
|
+
kosi = Kosi::Table.new({vertical_border_char: '#'})
|
219
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
220
|
+
</code></pre>
|
221
|
+
|
222
|
+
<p>出力 </p>
|
223
|
+
<pre><code>+-----+------+-------+
|
224
|
+
|a |b |c |
|
225
|
+
|ほゲ1|ひゲ22|へゲ333|
|
226
|
+
+-----+------+-------+
|
227
|
+
+-----+------+-------+
|
228
|
+
#a #b #c #
|
229
|
+
#ほゲ1#ひゲ22#へゲ333#
|
230
|
+
+-----+------+-------+
|
231
|
+
</code></pre>
|
232
|
+
|
233
|
+
<h3 id="複合オプション">複合オプション</h3>
|
234
|
+
<p>様々なオプションを一気に指定してみます</p>
|
235
|
+
<pre><code class="ruby">require 'kosi'
|
236
|
+
|
237
|
+
kosi = Kosi::Table.new(
|
238
|
+
{
|
239
|
+
align: Kosi::Align::TYPE::CENTER,
|
240
|
+
connector_char: 'x',
|
241
|
+
header: %w{column1 column2 column3},
|
242
|
+
horizontal_border_char: '*',
|
243
|
+
vertical_border_char: '#',
|
244
|
+
separate_each_row: true
|
245
|
+
}
|
246
|
+
)
|
247
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333'], [*'a'..'c']])
|
248
|
+
</code></pre>
|
249
|
+
|
250
|
+
<p>出力 </p>
|
251
|
+
<pre><code>x*******x*******x*******x
|
252
|
+
#column1#column2#column3#
|
253
|
+
x*******x*******x*******x
|
254
|
+
# a # b # c #
|
255
|
+
x*******x*******x*******x
|
256
|
+
# ほゲ1 #ひゲ22 #へゲ333#
|
257
|
+
x*******x*******x*******x
|
258
|
+
# a # b # c #
|
259
|
+
x*******x*******x*******x
|
260
|
+
</code></pre>
|
261
|
+
|
262
|
+
<h2 id="history">History</h2>
|
263
|
+
<p>version 0.0.1 : first release</p>
|
264
|
+
<h2 id="contributing">Contributing</h2>
|
265
|
+
<ol>
|
266
|
+
<li>Fork it ( https://github.com/[my-github-username]/kosi/fork )</li>
|
267
|
+
<li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
|
268
|
+
<li>Commit your changes (<code>git commit -am 'Add some feature'</code>)</li>
|
269
|
+
<li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
|
270
|
+
<li>Create a new Pull Request</li>
|
271
|
+
</ol>
|
272
|
+
</body>
|
273
|
+
</html>
|
data/README.md
ADDED
@@ -0,0 +1,290 @@
|
|
1
|
+
# Kosi
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tbpgr/kosi.png?branch=master)](https://travis-ci.org/tbpgr/kosi)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/tbpgr/kosi/badge.png)](https://coveralls.io/r/tbpgr/kosi)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/tbpgr/kosi.png)](https://codeclimate.com/github/tbpgr/kosi)
|
6
|
+
|
7
|
+
ターミナルアプリケーション用表フォーマットサポートツール。格子。
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'kosi'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install kosi
|
22
|
+
|
23
|
+
## Description
|
24
|
+
2次元配列をテーブルフォーマットにして出力します。
|
25
|
+
terminal-table gemの日本語対応版にあたります。
|
26
|
+
(terminal-tableはASCII対応のみなので全角文字が混ざるとテーブルレイアウトが崩れる)
|
27
|
+
|
28
|
+
具体的には
|
29
|
+
|
30
|
+
* Unicode 1-127 => ASCII。1文字分として計算
|
31
|
+
* Unicode 65377(0xff61)..65439(0xff9f) => 半角カナ。1文字分として計算
|
32
|
+
* その他 => 全角として扱う。2文字分として計算
|
33
|
+
|
34
|
+
## Options
|
35
|
+
### Align
|
36
|
+
配置指定。右寄せ、左寄せ、中央を選択可能。
|
37
|
+
|
38
|
+
| 設定可能パラメータ | 説明 |
|
39
|
+
|:-----------|:-----------|
|
40
|
+
|Kosi::Align::TYPE::RIGHT|右寄せ|
|
41
|
+
|Kosi::Align::TYPE::LEFT|左寄せ。デフォルト|
|
42
|
+
|Kosi::Align::TYPE::CENTER|中央|
|
43
|
+
|
44
|
+
### ConnectorChar
|
45
|
+
表の結合部に表示するテキスト。1文字で指定。
|
46
|
+
下記で言うところの 「+」がConnectorChar。
|
47
|
+
|
48
|
+
~~~
|
49
|
+
+-----+------+-------+
|
50
|
+
|a |b |c |
|
51
|
+
+-----+------+-------+
|
52
|
+
~~~
|
53
|
+
|
54
|
+
### Header
|
55
|
+
表のヘッダー。配列で指定。
|
56
|
+
デフォルトはヘッダーなし。
|
57
|
+
|
58
|
+
### HorizontalBorderChar
|
59
|
+
水平線を1文字で設定。
|
60
|
+
デフォルトは「-」
|
61
|
+
|
62
|
+
### SeparateEachRow
|
63
|
+
各行に区切り線を入れるかどうか。
|
64
|
+
デフォルトは「false」
|
65
|
+
|
66
|
+
### VerticalBorderChar
|
67
|
+
垂直線を1文字で設定。
|
68
|
+
デフォルトは「|」
|
69
|
+
|
70
|
+
## Usage
|
71
|
+
### オプション指定なし
|
72
|
+
~~~ruby
|
73
|
+
require 'kosi'
|
74
|
+
|
75
|
+
kosi = Kosi::Table.new
|
76
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
77
|
+
~~~
|
78
|
+
|
79
|
+
出力
|
80
|
+
※GitHubの表示上ずれているかもしれませんが、等幅フォント利用時にそろいます。
|
81
|
+
|
82
|
+
~~~
|
83
|
+
+-----+------+-------+
|
84
|
+
|a |b |c |
|
85
|
+
|ほゲ1|ひゲ22|へゲ333|
|
86
|
+
+-----+------+-------+
|
87
|
+
~~~
|
88
|
+
|
89
|
+
### Align指定
|
90
|
+
~~~ruby
|
91
|
+
require 'kosi'
|
92
|
+
|
93
|
+
kosi = Kosi::Table.new({align: Kosi::Align::TYPE::CENTER})
|
94
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
95
|
+
kosi = Kosi::Table.new({align: Kosi::Align::TYPE::RIGHT})
|
96
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
97
|
+
kosi = Kosi::Table.new({align: Kosi::Align::TYPE::LEFT})
|
98
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
99
|
+
~~~
|
100
|
+
|
101
|
+
出力
|
102
|
+
|
103
|
+
~~~
|
104
|
+
+-----+------+-------+
|
105
|
+
| a | b | c |
|
106
|
+
|ほゲ1|ひゲ22|へゲ333|
|
107
|
+
+-----+------+-------+
|
108
|
+
+-----+------+-------+
|
109
|
+
| a| b| c|
|
110
|
+
|ほゲ1|ひゲ22|へゲ333|
|
111
|
+
+-----+------+-------+
|
112
|
+
+-----+------+-------+
|
113
|
+
|a |b |c |
|
114
|
+
|ほゲ1|ひゲ22|へゲ333|
|
115
|
+
+-----+------+-------+
|
116
|
+
~~~
|
117
|
+
|
118
|
+
### ConnectorChar指定
|
119
|
+
~~~ruby
|
120
|
+
require 'kosi'
|
121
|
+
|
122
|
+
kosi = Kosi::Table.new
|
123
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
124
|
+
kosi = Kosi::Table.new({connector_char: 'x'})
|
125
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
126
|
+
kosi = Kosi::Table.new({connector_char: '$'})
|
127
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
128
|
+
~~~
|
129
|
+
|
130
|
+
出力
|
131
|
+
|
132
|
+
~~~
|
133
|
+
+-----+------+-------+
|
134
|
+
|a |b |c |
|
135
|
+
|ほゲ1|ひゲ22|へゲ333|
|
136
|
+
+-----+------+-------+
|
137
|
+
x-----x------x-------x
|
138
|
+
|a |b |c |
|
139
|
+
|ほゲ1|ひゲ22|へゲ333|
|
140
|
+
x-----x------x-------x
|
141
|
+
$-----$------$-------$
|
142
|
+
|a |b |c |
|
143
|
+
|ほゲ1|ひゲ22|へゲ333|
|
144
|
+
$-----$------$-------$
|
145
|
+
~~~
|
146
|
+
|
147
|
+
|
148
|
+
### Header指定
|
149
|
+
~~~ruby
|
150
|
+
require 'kosi'
|
151
|
+
|
152
|
+
kosi = Kosi::Table.new
|
153
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
154
|
+
kosi = Kosi::Table.new({header: %w{column1 column2 column3}})
|
155
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
156
|
+
~~~
|
157
|
+
|
158
|
+
|
159
|
+
出力
|
160
|
+
|
161
|
+
~~~
|
162
|
+
+-----+------+-------+
|
163
|
+
|a |b |c |
|
164
|
+
|ほゲ1|ひゲ22|へゲ333|
|
165
|
+
+-----+------+-------+
|
166
|
+
+-------+-------+-------+
|
167
|
+
|column1|column2|column3|
|
168
|
+
+-------+-------+-------+
|
169
|
+
|a |b |c |
|
170
|
+
|ほゲ1 |ひゲ22 |へゲ333|
|
171
|
+
+-------+-------+-------+
|
172
|
+
~~~
|
173
|
+
|
174
|
+
### HorizontalBorderChar指定
|
175
|
+
~~~ruby
|
176
|
+
require 'kosi'
|
177
|
+
|
178
|
+
kosi = Kosi::Table.new
|
179
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
180
|
+
kosi = Kosi::Table.new({horizontal_border_char: '*'})
|
181
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
182
|
+
~~~
|
183
|
+
|
184
|
+
出力
|
185
|
+
|
186
|
+
~~~
|
187
|
+
+-----+------+-------+
|
188
|
+
|a |b |c |
|
189
|
+
|ほゲ1|ひゲ22|へゲ333|
|
190
|
+
+-----+------+-------+
|
191
|
+
+*****+******+*******+
|
192
|
+
|a |b |c |
|
193
|
+
|ほゲ1|ひゲ22|へゲ333|
|
194
|
+
+*****+******+*******+
|
195
|
+
~~~
|
196
|
+
|
197
|
+
### SeparateEachRow指定
|
198
|
+
~~~ruby
|
199
|
+
require 'kosi'
|
200
|
+
|
201
|
+
kosi = Kosi::Table.new
|
202
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333'], [*'a'..'c']])
|
203
|
+
kosi = Kosi::Table.new({separate_each_row: true})
|
204
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333'], [*'a'..'c']])
|
205
|
+
~~~
|
206
|
+
|
207
|
+
出力
|
208
|
+
|
209
|
+
~~~
|
210
|
+
+-----+------+-------+
|
211
|
+
|a |b |c |
|
212
|
+
|ほゲ1|ひゲ22|へゲ333|
|
213
|
+
|a |b |c |
|
214
|
+
+-----+------+-------+
|
215
|
+
+-----+------+-------+
|
216
|
+
|a |b |c |
|
217
|
+
+-----+------+-------+
|
218
|
+
|ほゲ1|ひゲ22|へゲ333|
|
219
|
+
+-----+------+-------+
|
220
|
+
|a |b |c |
|
221
|
+
+-----+------+-------+
|
222
|
+
~~~
|
223
|
+
|
224
|
+
### VerticalBorderChar指定
|
225
|
+
~~~ruby
|
226
|
+
require 'kosi'
|
227
|
+
|
228
|
+
kosi = Kosi::Table.new
|
229
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
230
|
+
kosi = Kosi::Table.new({vertical_border_char: '#'})
|
231
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333']])
|
232
|
+
~~~
|
233
|
+
|
234
|
+
出力
|
235
|
+
|
236
|
+
~~~
|
237
|
+
+-----+------+-------+
|
238
|
+
|a |b |c |
|
239
|
+
|ほゲ1|ひゲ22|へゲ333|
|
240
|
+
+-----+------+-------+
|
241
|
+
+-----+------+-------+
|
242
|
+
#a #b #c #
|
243
|
+
#ほゲ1#ひゲ22#へゲ333#
|
244
|
+
+-----+------+-------+
|
245
|
+
~~~
|
246
|
+
|
247
|
+
### 複合オプション
|
248
|
+
様々なオプションを一気に指定してみます
|
249
|
+
|
250
|
+
~~~ruby
|
251
|
+
require 'kosi'
|
252
|
+
|
253
|
+
kosi = Kosi::Table.new(
|
254
|
+
{
|
255
|
+
align: Kosi::Align::TYPE::CENTER,
|
256
|
+
connector_char: 'x',
|
257
|
+
header: %w{column1 column2 column3},
|
258
|
+
horizontal_border_char: '*',
|
259
|
+
vertical_border_char: '#',
|
260
|
+
separate_each_row: true
|
261
|
+
}
|
262
|
+
)
|
263
|
+
print kosi.render([[*'a'..'c'], ['ほゲ1', 'ひゲ22', 'へゲ333'], [*'a'..'c']])
|
264
|
+
~~~
|
265
|
+
|
266
|
+
出力
|
267
|
+
|
268
|
+
~~~
|
269
|
+
x*******x*******x*******x
|
270
|
+
#column1#column2#column3#
|
271
|
+
x*******x*******x*******x
|
272
|
+
# a # b # c #
|
273
|
+
x*******x*******x*******x
|
274
|
+
# ほゲ1 #ひゲ22 #へゲ333#
|
275
|
+
x*******x*******x*******x
|
276
|
+
# a # b # c #
|
277
|
+
x*******x*******x*******x
|
278
|
+
~~~
|
279
|
+
|
280
|
+
## History
|
281
|
+
|
282
|
+
version 0.0.1 : first release
|
283
|
+
|
284
|
+
## Contributing
|
285
|
+
|
286
|
+
1. Fork it ( https://github.com/tbpgr/kosi/fork )
|
287
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
288
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
289
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
290
|
+
5. Create a new Pull Request
|