Class: ProgressBar::Base
Constant Summary
collapse
- DEFAULT_OUTPUT_STREAM =
$stdout
Constants included
from Formatter
Formatter::DEFAULT_FORMAT_STRING, Formatter::DEFAULT_NON_TTY_FORMAT_STRING, Formatter::DEFAULT_TITLE
Instance Method Summary
collapse
Methods included from Formatter
#format, #progress, #total
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
Instance Method Details
#clear ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/ruby-progressbar/base.rb', line 114
def clear
self.last_update_length = 0
if output.tty?
output.print clear_string
output.print "\r"
else
output.print "\n"
end
end
|
#decrement ⇒ Object
Updating The Bar’s Progress
38
39
40
|
# File 'lib/ruby-progressbar/base.rb', line 38
def decrement
update_progress(:decrement)
end
|
#finish ⇒ Object
57
58
59
|
# File 'lib/ruby-progressbar/base.rb', line 57
def finish
with_update { with_progressables(:finish); with_timers(:stop) } unless finished?
end
|
#finished? ⇒ Boolean
86
87
88
|
# File 'lib/ruby-progressbar/base.rb', line 86
def finished?
@estimated_time.finished? && @bar.finished?
end
|
#increment ⇒ Object
42
43
44
|
# File 'lib/ruby-progressbar/base.rb', line 42
def increment
update_progress(:increment)
end
|
#inspect ⇒ Object
142
143
144
|
# File 'lib/ruby-progressbar/base.rb', line 142
def inspect
"#<ProgressBar:#{progress}/#{total || 'unknown'}>"
end
|
#log(string) ⇒ Object
129
130
131
132
133
134
|
# File 'lib/ruby-progressbar/base.rb', line 129
def log(string)
clear
output.puts string
update(:force => true) unless stopped?
end
|
#pause ⇒ Object
61
62
63
|
# File 'lib/ruby-progressbar/base.rb', line 61
def pause
with_update { with_timers(:pause) } unless paused?
end
|
#progress=(new_progress) ⇒ Object
46
47
48
|
# File 'lib/ruby-progressbar/base.rb', line 46
def progress=(new_progress)
update_progress(:progress=, new_progress)
end
|
#progress_mark=(mark) ⇒ Object
97
98
99
|
# File 'lib/ruby-progressbar/base.rb', line 97
def progress_mark=(mark)
with_update { @bar.progress_mark = mark }
end
|
#refresh ⇒ Object
125
126
127
|
# File 'lib/ruby-progressbar/base.rb', line 125
def refresh
update
end
|
#remainder_mark=(mark) ⇒ Object
101
102
103
|
# File 'lib/ruby-progressbar/base.rb', line 101
def remainder_mark=(mark)
with_update { @bar.remainder_mark = mark }
end
|
#reset ⇒ Object
73
74
75
76
77
78
|
# File 'lib/ruby-progressbar/base.rb', line 73
def reset
with_update do
@bar.reset
with_timers(:reset)
end
end
|
#resume ⇒ Object
69
70
71
|
# File 'lib/ruby-progressbar/base.rb', line 69
def resume
with_update { with_timers(:resume) } if stopped?
end
|
#start(options = {}) ⇒ Object
26
27
28
29
30
31
32
33
|
# File 'lib/ruby-progressbar/base.rb', line 26
def start(options = {})
clear
with_update do
with_progressables(:start, options)
with_timers(:start)
end
end
|
#started? ⇒ Boolean
90
91
92
|
# File 'lib/ruby-progressbar/base.rb', line 90
def started?
@estimated_time.started? && @elapsed_time.started? && @bar.started?
end
|
#stop ⇒ Object
65
66
67
|
# File 'lib/ruby-progressbar/base.rb', line 65
def stop
with_update { with_timers(:stop) } unless stopped?
end
|
#stopped? ⇒ Boolean
Also known as:
paused?
80
81
82
|
# File 'lib/ruby-progressbar/base.rb', line 80
def stopped?
(@estimated_time.stopped? && @elapsed_time.stopped?) || finished?
end
|
#title=(title) ⇒ Object
105
106
107
108
109
|
# File 'lib/ruby-progressbar/base.rb', line 105
def title=(title)
if output.tty?
with_update { super }
end
end
|
#to_s(format_string = nil) ⇒ Object
136
137
138
139
140
|
# File 'lib/ruby-progressbar/base.rb', line 136
def to_s(format_string = nil)
format_string ||= @format_string
format(format_string)
end
|
#total=(new_total) ⇒ Object
50
51
52
|
# File 'lib/ruby-progressbar/base.rb', line 50
def total=(new_total)
update_progress(:total=, new_total)
end
|