Class: Wp2txt::ProgressBar
- Inherits:
-
Object
- Object
- Wp2txt::ProgressBar
show all
- Defined in:
- lib/wp2txt/progressbar.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(title, total, out = STDERR) ⇒ ProgressBar
Returns a new instance of ProgressBar.
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/wp2txt/progressbar.rb', line 17
def initialize (title, total, out = STDERR)
@title = title
@total = total
@out = out
@terminal_width = 80
@bar_mark = "o"
@current = 0
@previous = 0
@finished_p = false
@start_time = Time.now
@previous_time = @start_time
@title_width = 14
@format = "%-#{@title_width}s %3d%% %s %s"
@format_arguments = [:title, :percentage, :bar, :stat]
clear
show
end
|
Instance Attribute Details
#current ⇒ Object
Returns the value of attribute current.
35
36
37
|
# File 'lib/wp2txt/progressbar.rb', line 35
def current
@current
end
|
#start_time ⇒ Object
Returns the value of attribute start_time.
37
38
39
|
# File 'lib/wp2txt/progressbar.rb', line 37
def start_time
@start_time
end
|
#title ⇒ Object
Returns the value of attribute title.
34
35
36
|
# File 'lib/wp2txt/progressbar.rb', line 34
def title
@title
end
|
#total ⇒ Object
Returns the value of attribute total.
36
37
38
|
# File 'lib/wp2txt/progressbar.rb', line 36
def total
@total
end
|
Instance Method Details
#clear ⇒ Object
179
180
181
182
183
|
# File 'lib/wp2txt/progressbar.rb', line 179
def clear
@out.print "\r"
@out.print(" " * (get_width - 1))
@out.print "\r"
end
|
#file_transfer_mode ⇒ Object
195
196
197
|
# File 'lib/wp2txt/progressbar.rb', line 195
def file_transfer_mode
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
end
|
#finish ⇒ Object
185
186
187
188
189
|
# File 'lib/wp2txt/progressbar.rb', line 185
def finish
@current = @total
@finished_p = true
show
end
|
#finished? ⇒ Boolean
191
192
193
|
# File 'lib/wp2txt/progressbar.rb', line 191
def finished?
@finished_p
end
|
199
200
201
|
# File 'lib/wp2txt/progressbar.rb', line 199
def format= (format)
@format = format
end
|
203
204
205
|
# File 'lib/wp2txt/progressbar.rb', line 203
def format_arguments= (arguments)
@format_arguments = arguments
end
|
#halt ⇒ Object
207
208
209
210
|
# File 'lib/wp2txt/progressbar.rb', line 207
def halt
@finished_p = true
show
end
|
#inc(step = 1) ⇒ Object
212
213
214
215
216
217
|
# File 'lib/wp2txt/progressbar.rb', line 212
def inc (step = 1)
@current += step
@current = @total if @current > @total
show_if_needed
@previous = @current
end
|
#inspect ⇒ Object
228
229
230
|
# File 'lib/wp2txt/progressbar.rb', line 228
def inspect
"#<ProgressBar:#{@current}/#{@total}>"
end
|
#set(count) ⇒ Object
219
220
221
222
223
224
225
226
|
# File 'lib/wp2txt/progressbar.rb', line 219
def set (count)
if count < 0 || count > @total
raise "invalid count: #{count} (total: #{@total})"
end
@current = count
show_if_needed
@previous = @current
end
|