Class: Archive::Tar::Minitar::Command::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb

Constant Summary collapse

VERSION =
"0.8"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ProgressBar.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 35

def initialize (title, total, out = STDERR)
  @title = title
  @total = total
  @out = out
  @bar_width = 80
  @bar_mark = "o"
  @current = 0
  @previous = 0
  @is_finished = 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]
  show
end

Instance Attribute Details

#title=(value) ⇒ Object

Sets the attribute title

Parameters:

  • value

    the value to set the attribute title to.



33
34
35
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 33

def title=(value)
  @title = value
end

#totalObject

Returns the value of attribute total.



32
33
34
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 32

def total
  @total
end

Instance Method Details

#file_transfer_modeObject



182
183
184
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 182

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

#finishObject



194
195
196
197
198
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 194

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

#format=(format) ⇒ Object



186
187
188
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 186

def format= (format)
  @format = format
end

#format_arguments=(arguments) ⇒ Object



190
191
192
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 190

def format_arguments= (arguments)
  @format_arguments = arguments
end

#haltObject



200
201
202
203
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 200

def halt
  @is_finished = true
  show_progress
end

#inc(step = 1) ⇒ Object



214
215
216
217
218
219
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 214

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

#inspectObject



221
222
223
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 221

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

#set(count) ⇒ Object



205
206
207
208
209
210
211
212
# File 'lib/gems/archive-tar-minitar-0.5.2/lib/archive/tar/minitar/command.rb', line 205

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