Class: Progress
- Inherits:
-
Object
- Object
- Progress
- Defined in:
- lib/piggy-core/progress.rb
Overview
Interface to monitor progress of long running tasks.
Direct Known Subclasses
Instance Method Summary collapse
- #cancel ⇒ Object
- #continue? ⇒ Boolean
- #finish ⇒ Object
-
#initialize ⇒ Progress
constructor
A new instance of Progress.
- #log_progress(message, unit) ⇒ Object
- #log_task ⇒ Object
- #set_progress(message = ".", unit = 1) ⇒ Object
- #set_task(task, num_units = 1) ⇒ Object
Constructor Details
#initialize ⇒ Progress
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
#cancel ⇒ Object
12 13 14 |
# File 'lib/piggy-core/progress.rb', line 12 def cancel @cancel = true end |
#continue? ⇒ Boolean
16 17 18 |
# File 'lib/piggy-core/progress.rb', line 16 def continue? !@cancel end |
#finish ⇒ Object
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(, unit) if( == ".") put else puts end end |
#log_task ⇒ Object
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(=".", unit=1) @units = @units + unit log_progress(, 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 |