Class: ProgressBar::Output
- Inherits:
-
Object
- Object
- ProgressBar::Output
show all
- Defined in:
- lib/ruby-progressbar/output.rb
Constant Summary
collapse
- DEFAULT_OUTPUT_STREAM =
$stdout
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Output
Returns a new instance of Output.
10
11
12
13
14
15
16
17
18
|
# File 'lib/ruby-progressbar/output.rb', line 10
def initialize(options = {})
self.bar = options[:bar]
self.stream = options[:output] || DEFAULT_OUTPUT_STREAM
self.throttle = Throttle.new(options)
self.length_calculator = Calculators::Length.new(
:length => options[:length],
:output => stream
)
end
|
Instance Attribute Details
#stream ⇒ Object
Returns the value of attribute stream.
8
9
10
|
# File 'lib/ruby-progressbar/output.rb', line 8
def stream
@stream
end
|
Class Method Details
.detect(options = {}) ⇒ Object
Instance Method Details
#clear_string ⇒ Object
37
38
39
|
# File 'lib/ruby-progressbar/output.rb', line 37
def clear_string
' ' * length_calculator.length
end
|
#length ⇒ Object
41
42
43
|
# File 'lib/ruby-progressbar/output.rb', line 41
def length
length_calculator.length
end
|
#log(string) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/ruby-progressbar/output.rb', line 30
def log(string)
clear
stream.puts string
refresh(:force => true) unless bar.stopped?
end
|
#refresh(options = {}) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/ruby-progressbar/output.rb', line 50
def refresh(options = {})
throttle.choke(:force_update_if => (bar.stopped? || options[:force])) do
clear if length_calculator.length_changed?
print_and_flush
end
end
|
#with_refresh ⇒ Object
45
46
47
48
|
# File 'lib/ruby-progressbar/output.rb', line 45
def with_refresh
yield
refresh
end
|