Class: ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/taps/progress_bar.rb

Overview

Ruby/ProgressBar - a text progress bar library

Copyright © 2001-2005 Satoru Takabayashi <[email protected]>

All rights reserved.
This is free software with ABSOLUTELY NO WARRANTY.

You can redistribute it and/or modify it under the terms of Ruby’s license.

Direct Known Subclasses

ReversedProgressBar

Constant Summary collapse

VERSION =
"0.9"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, total, out = STDERR) ⇒ ProgressBar

Returns a new instance of ProgressBar.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/taps/progress_bar.rb', line 15

def initialize (title, total, out = STDERR)
  @title = title
  @total = total
  @out = out
  @terminal_width = 80
  @bar_mark = "="
  @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

#currentObject (readonly)

Returns the value of attribute current.



33
34
35
# File 'lib/taps/progress_bar.rb', line 33

def current
  @current
end

#start_timeObject

Returns the value of attribute start_time.



35
36
37
# File 'lib/taps/progress_bar.rb', line 35

def start_time
  @start_time
end

#titleObject (readonly)

Returns the value of attribute title.



32
33
34
# File 'lib/taps/progress_bar.rb', line 32

def title
  @title
end

#totalObject (readonly)

Returns the value of attribute total.



34
35
36
# File 'lib/taps/progress_bar.rb', line 34

def total
  @total
end

Instance Method Details

#clearObject



177
178
179
180
181
# File 'lib/taps/progress_bar.rb', line 177

def clear
  @out.print "\r"
  @out.print(" " * (get_width - 1))
  @out.print "\r"
end

#file_transfer_modeObject



193
194
195
# File 'lib/taps/progress_bar.rb', line 193

def file_transfer_mode
  @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
end

#finishObject



183
184
185
186
187
# File 'lib/taps/progress_bar.rb', line 183

def finish
  @current = @total
  @finished_p = true
  show
end

#finished?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/taps/progress_bar.rb', line 189

def finished?
  @finished_p
end

#format=(format) ⇒ Object



197
198
199
# File 'lib/taps/progress_bar.rb', line 197

def format= (format)
  @format = format
end

#format_arguments=(arguments) ⇒ Object



201
202
203
# File 'lib/taps/progress_bar.rb', line 201

def format_arguments= (arguments)
  @format_arguments = arguments
end

#haltObject



205
206
207
208
# File 'lib/taps/progress_bar.rb', line 205

def halt
  @finished_p = true
  show
end

#inc(step = 1) ⇒ Object



210
211
212
213
214
215
# File 'lib/taps/progress_bar.rb', line 210

def inc (step = 1)
  @current += step
  @current = @total if @current > @total
  show_if_needed
  @previous = @current
end

#inspectObject



226
227
228
# File 'lib/taps/progress_bar.rb', line 226

def inspect
  "#<ProgressBar:#{@current}/#{@total}>"
end

#set(count) ⇒ Object



217
218
219
220
221
222
223
224
# File 'lib/taps/progress_bar.rb', line 217

def set (count)
  if count < 0 || count > @total
    raise "invalid count: #{count} (total: #{@total})"
  end
  @current = count
  show_if_needed
  @previous = @current
end