Class: TheFox::Timr::ProgressBar
- Inherits:
-
Object
- Object
- TheFox::Timr::ProgressBar
- Defined in:
- lib/timr/progressbar.rb
Overview
See [ruby-progressbar Issue #131](github.com/jfelchner/ruby-progressbar/issues/131).
Instance Method Summary collapse
-
#initialize(options = Hash.new) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
-
#render(progress = nil) ⇒ Object
Render ProgressBar as String.
Constructor Details
#initialize(options = Hash.new) ⇒ ProgressBar
Returns a new instance of ProgressBar.
8 9 10 11 12 13 14 |
# File 'lib/timr/progressbar.rb', line 8 def initialize( = Hash.new) @total = .fetch(:total, 100) @progress = .fetch(:progress, 0) @length = .fetch(:length, 10) @progress_mark = .fetch(:progress_mark, ?#) @remainder_mark = .fetch(:remainder_mark, ?-) end |
Instance Method Details
#render(progress = nil) ⇒ Object
Render ProgressBar as String.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/timr/progressbar.rb', line 17 def render(progress = nil) if progress @progress = progress end progress_f = @progress.to_f / @total.to_f if progress_f > 1.0 progress_f = 1.0 end progress_f = @length.to_f * progress_f progress_s = @progress_mark * progress_f remain_l = @length - progress_s.length remain_s = @remainder_mark * remain_l '%s%s' % [progress_s, remain_s] end |