プログレスバーを簡単に。each_with_animというRubyのgemを作りました。
RubyのCUI上でループ時のアニメーションが楽に作れる,"each_with_anim"というgemを作りました!
require "each_with_anim"するだけでArrayとかHashとかにeach_with_animメソッドが追加されます。
ループが終了する残り時間も推測してくれる機能付き。
Rubyのプログラムを書くとき,これがあるとちょっと便利。
使い方
each_with_animはeachと同じように使えます。
eachと同じ振る舞いをしつつ,ループの進行状況を表すアニメーションが追加されます。
require "each_with_anim" array = ["huga", "hoge", "foo", ... ] array.each_with_anim do |elem| #something end
with_indexとかもeachと同じように使えます。
あとeach_with_animationと書いてもeach_with_animと同じ働きをします。
array = (1..3000).to_a array.each_with_animation.with_index do |elem,i| #something end
同様に,引数を取ってアニメーションを変えることができます。今後増やして行く予定。
list = %w(hage hoge foo) * 100 list.each_with_anim(1) do |elem| #something end
インストール方法
$ gem install each_with_anim
で引っ張って来て,
require "each_with_anim"
requireするだけ。
あとは好きなようにHashでもArrayでも.each_with_animしちゃってください。
現状の問題
each_with_animに渡すブロック内でprintすると表示がバグります。
解決策を絶賛探し中。
list = %w(hage hoge foo) * 10 list.each_with_anim do |elem| puts "piyoo" end
Rubyのプログレスバー系で一番見た目が美しく,簡単で便利なものを目指しました。
初めてライブラリ作ったのでまぁお手柔らかにお願いします笑
時間がかかるようなeach処理のとき,例えばActiveRecordとかで大量のデータを書き込むときとか,これがあるとちょっと便利だと思います。
License
The gem is available as open source under the terms of the MIT License.
自由に使ってください。