Class: Console::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/contrib/progressbar.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ProgressBar.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/contrib/progressbar.rb', line 39

def initialize(title, total, out = STDERR)
  @title = title
  @total = total
  @out = out
  @bar_length = 80
  @bar_mark = "o"
  @total_overflow = true
  @current = 0
  @previous = 0
  @is_finished = false
  @start_time = Time.now
  @format = "%-14s %3d%% %s %s"
  @format_arguments = [:title, :percentage, :bar, :stat]
  show_progress
end

Instance Method Details

#bar_mark=(mark) ⇒ Object



186
187
188
# File 'lib/contrib/progressbar.rb', line 186

def bar_mark= (mark)
  @bar_mark = String(mark)[0..0]
end

#file_transfer_modeObject



182
183
184
# File 'lib/contrib/progressbar.rb', line 182

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

#finishObject



202
203
204
205
206
# File 'lib/contrib/progressbar.rb', line 202

def finish
  @current = @total
  @is_finished = true
  show_progress
end

#format=(format) ⇒ Object



194
195
196
# File 'lib/contrib/progressbar.rb', line 194

def format= (format)
  @format = format
end

#format_arguments=(arguments) ⇒ Object



198
199
200
# File 'lib/contrib/progressbar.rb', line 198

def format_arguments= (arguments)
  @format_arguments = arguments
end

#haltObject



208
209
210
211
# File 'lib/contrib/progressbar.rb', line 208

def halt
  @is_finished = true
  show_progress
end

#inc(step = 1) ⇒ Object



228
229
230
231
232
233
# File 'lib/contrib/progressbar.rb', line 228

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

#inspectObject



235
236
237
# File 'lib/contrib/progressbar.rb', line 235

def inspect
  "(ProgressBar: #{@current}/#{@total})"
end

#set(count) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/contrib/progressbar.rb', line 213

def set (count)
  if count < 0
    raise "invalid count less than zero: #{count}"
  elsif count > @total
    if @total_overflow
      @total = count + 1
    else
      raise "invalid count greater than total: #{count}"
    end
  end
  @current = count
  show_progress
  @previous = @current
end

#total_overflow=(boolv) ⇒ Object



190
191
192
# File 'lib/contrib/progressbar.rb', line 190

def total_overflow= (boolv)
  @total_overflow = boolv ? true : false
end