Class: Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/piggy-core/progress.rb

Overview

Interface to monitor progress of long running tasks.

Direct Known Subclasses

ProgressWithDialog

Instance Method Summary collapse

Constructor Details

#initializeProgress

Returns a new instance of Progress.



5
6
7
8
9
10
# File 'lib/piggy-core/progress.rb', line 5

def initialize
  @task = "Processing"
  @numUnits = 1
  @units = 0
  @cancel = false
end

Instance Method Details

#cancelObject



12
13
14
# File 'lib/piggy-core/progress.rb', line 12

def cancel
  @cancel = true
end

#continue?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/piggy-core/progress.rb', line 16

def continue?
  !@cancel
end

#finishObject



46
47
# File 'lib/piggy-core/progress.rb', line 46

def finish
end

#log_progress(message, unit) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/piggy-core/progress.rb', line 38

def log_progress(message, unit)
  if(message == ".")
    put message
  else
    puts message
  end
end

#log_taskObject



28
29
30
# File 'lib/piggy-core/progress.rb', line 28

def log_task
  puts "Now working on Task #{@task} (#{@numUnits} units)"
end

#set_progress(message = ".", unit = 1) ⇒ Object



32
33
34
35
36
# File 'lib/piggy-core/progress.rb', line 32

def set_progress(message=".", unit=1)
  @units = @units + unit
  log_progress(message, unit)
  return continue?
end

#set_task(task, num_units = 1) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/piggy-core/progress.rb', line 20

def set_task(task, num_units=1)
  @units = 0
  @task = task
  @numUnits = num_units
  log_task
  return continue?
end