Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
テキストで表を簡単に作るライブラリ
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
spec
.gitignore
Gemfile
README.org
Rakefile
rain_table.gemspec

README.org

オブジェクトを表にするライブラリ

tt [{:id => 1, :name => "alice"}, {:id => 2, :name => "bob"}]
# >> +----+-------+
# >> | id | name  |
# >> +----+-------+
# >> |  1 | alice |
# >> |  2 | bob   |
# >> +----+-------+
tt({:id => 1, :name => "alice"})
# >> +------+-------+
# >> | id   |     1 |
# >> | name | alice |
# >> +------+-------+

あんまり意味ないけど

tt 1
# >> +---+
# >> | 1 |
# >> +---+
tt "foo"
# >> +-----+
# >> | foo |
# >> +-----+
tt :foo
# >> +-----+
# >> | foo |
# >> +-----+

ActiveRecord の場合ちょっと見やすくする

["alice", "bob"].each{|name| User.create!(:name => name) }
tt User
# >> +----+-------+
# >> | id | name  |
# >> +----+-------+
# >> |  1 | alice |
# >> |  2 | bob   |
# >> +----+-------+
tt User.limit(1)
# >> +----+-------+
# >> | id | name  |
# >> +----+-------+
# >> |  1 | alice |
# >> +----+-------+
tt User.first
# >> +------+-------+
# >> | id   |     1 |
# >> | name | alice |
# >> +------+-------+

文字列にする場合

puts [{:id => 1, :name => "alice"}, {:id => 2, :name => "bob"}].to_t
# >> +----+-------+
# >> | id | name  |
# >> +----+-------+
# >> |  1 | alice |
# >> |  2 | bob   |
# >> +----+-------+

TableFomatter とインタフェース互換

header = ["ID", "名前"]
rows = [[1, "alice"], [2, "bob"]]
puts RainTable::TableFormatter.format(header, rows)
+----+-------+
| ID | 名前  |
+----+-------+
|  1 | alice |
|  2 | bob   |
+----+-------+
Something went wrong with that request. Please try again.