Class: ProgressBar
- Inherits:
-
Object
- Object
- ProgressBar
- Defined in:
- lib/rbsync.rb
Overview
プログレスバーを表示する.
prg= ProgressBar.new
prg.show_percent = true
prg.size = 60
prg.start("downloading\n")
100.times{|i|
prg.progress(i, "#{i}/100")
sleep 0.015
}
prg.end("done")
Instance Attribute Summary collapse
-
#bar_char_done ⇒ Object
Returns the value of attribute bar_char_done.
-
#bar_char_undone ⇒ Object
Returns the value of attribute bar_char_undone.
-
#out ⇒ Object
Returns the value of attribute out.
-
#show_percent ⇒ Object
Returns the value of attribute show_percent.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #clear ⇒ Object
- #end(message = "") ⇒ Object
-
#initialize ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #progress(percent, message = nil) ⇒ Object
- #start(message = "") ⇒ Object
Constructor Details
#initialize ⇒ ProgressBar
Returns a new instance of ProgressBar.
514 515 516 517 518 519 520 521 |
# File 'lib/rbsync.rb', line 514 def initialize() @out = $stdout @size = 10 @bar_char_undone = "_" @bar_char_done = "#" @show_percent = true @printend_max_size = 0 end |
Instance Attribute Details
#bar_char_done ⇒ Object
Returns the value of attribute bar_char_done.
513 514 515 |
# File 'lib/rbsync.rb', line 513 def @bar_char_done end |
#bar_char_undone ⇒ Object
Returns the value of attribute bar_char_undone.
513 514 515 |
# File 'lib/rbsync.rb', line 513 def @bar_char_undone end |
#out ⇒ Object
Returns the value of attribute out.
513 514 515 |
# File 'lib/rbsync.rb', line 513 def out @out end |
#show_percent ⇒ Object
Returns the value of attribute show_percent.
513 514 515 |
# File 'lib/rbsync.rb', line 513 def show_percent @show_percent end |
#size ⇒ Object
Returns the value of attribute size.
513 514 515 |
# File 'lib/rbsync.rb', line 513 def size @size end |
Instance Method Details
#clear ⇒ Object
533 534 535 536 537 538 |
# File 'lib/rbsync.rb', line 533 def clear() out.print "\r" line_size = [@printend_max_size, @size].max out.print " " * line_size out.flush end |
#end(message = "") ⇒ Object
527 528 529 530 531 532 |
# File 'lib/rbsync.rb', line 527 def end(="") progress(100) out.print " " + out.puts "" out.flush end |
#progress(percent, message = nil) ⇒ Object
539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/rbsync.rb', line 539 def progress(percent,=nil) clear() str ="" str << "\r" str << * ((percent.to_f/100.to_f)*size).to_i str << * (size - ((percent.to_f/100.to_f)*size).to_i) str << " " + percent.to_s + "%" if show_percent str << " " + if @printend_max_size = str.size if str.size > @printend_max_size out.print str out.flush end |
#start(message = "") ⇒ Object
522 523 524 525 526 |
# File 'lib/rbsync.rb', line 522 def start(="") out.puts out.print * size out.flush end |