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.
7
8
9
10
11
12
|
# File 'lib/ruby-progressbar/output.rb', line 7
def initialize(options = {})
self.bar = options[:bar]
self.stream = options[:output] || DEFAULT_OUTPUT_STREAM
self.length_calculator = Calculators::Length.new(options)
self.throttle = Throttle.new(options)
end
|
Instance Attribute Details
#stream ⇒ Object
Returns the value of attribute stream.
5
6
7
|
# File 'lib/ruby-progressbar/output.rb', line 5
def stream
@stream
end
|
Class Method Details
.detect(options = {}) ⇒ Object
Instance Method Details
#clear_string ⇒ Object
29
30
31
|
# File 'lib/ruby-progressbar/output.rb', line 29
def clear_string
' ' * length_calculator.length
end
|
#length ⇒ Object
33
34
35
|
# File 'lib/ruby-progressbar/output.rb', line 33
def length
length_calculator.length
end
|
#log(string) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/ruby-progressbar/output.rb', line 22
def log(string)
clear
stream.puts string
refresh(:force => true) unless bar.stopped?
end
|
#print_and_flush ⇒ Object
50
51
52
53
|
# File 'lib/ruby-progressbar/output.rb', line 50
def print_and_flush
stream.print bar_update_string + eol
stream.flush
end
|
#refresh(options = {}) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/ruby-progressbar/output.rb', line 42
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
37
38
39
40
|
# File 'lib/ruby-progressbar/output.rb', line 37
def with_refresh
yield
refresh
end
|