Code Coverage
 
Lines
Covered
100.00% covered (success)
100.00%
20 / 20
1
module TheFox
1
module Timr
# See [ruby-progressbar Issue #131](https://github.com/jfelchner/ruby-progressbar/issues/131).
1
class ProgressBar
1
def initialize(options = Hash.new)
6
@total = options.fetch(:total, 100)
6
@progress = options.fetch(:progress, 0)
6
@length = options.fetch(:length, 10)
6
@progress_mark = options.fetch(:progress_mark, ?#)
6
@remainder_mark = options.fetch(:remainder_mark, ?-)
end
# Render ProgressBar as String.
1
def render(progress = nil)
16
if progress
10
@progress = progress
end
16
progress_f = @progress.to_f / @total.to_f
16
if progress_f > 1.0
1
progress_f = 1.0
end
16
progress_f = @length.to_f * progress_f
16
progress_s = @progress_mark * progress_f
16
remain_l = @length - progress_s.length
16
remain_s = @remainder_mark * remain_l
16
'%s%s' % [progress_s, remain_s]
end
end # class ProgressBar
end # module Timr
end # module TheFox