This repository has been archived by the owner. It is now read-only.
Hashの配列等から直接テキストの表を作る旧ライブラリ(org_tp gem に移行しました)
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
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   |
# >> +----+-------+