Class: Rich::ProgressTask
- Inherits:
-
Object
- Object
- Rich::ProgressTask
- Defined in:
- lib/rich/progress.rb
Overview
A task in progress tracking
Instance Attribute Summary collapse
-
#completed ⇒ Integer
readonly
Completed steps.
-
#description ⇒ String
readonly
Task description.
-
#end_time ⇒ Time?
readonly
End time.
-
#finished ⇒ Boolean
readonly
Task is finished.
-
#start_time ⇒ Time
readonly
Start time.
-
#total ⇒ Integer
readonly
Total steps.
Instance Method Summary collapse
-
#advance(steps = 1) ⇒ Object
Update progress.
-
#elapsed ⇒ Float?
Elapsed time.
-
#finish ⇒ Object
Mark as finished.
-
#initialize(description:, total: 100) ⇒ ProgressTask
constructor
A new instance of ProgressTask.
-
#progress ⇒ Float
Progress fraction.
-
#update(value) ⇒ Object
Set completed directly.
Constructor Details
#initialize(description:, total: 100) ⇒ ProgressTask
Returns a new instance of ProgressTask.
271 272 273 274 275 276 277 278 |
# File 'lib/rich/progress.rb', line 271 def initialize(description:, total: 100) @description = description @total = total @completed = 0 @finished = false @start_time = Time.now @end_time = nil end |
Instance Attribute Details
#completed ⇒ Integer (readonly)
Returns Completed steps.
260 261 262 |
# File 'lib/rich/progress.rb', line 260 def completed @completed end |
#description ⇒ String (readonly)
Returns Task description.
254 255 256 |
# File 'lib/rich/progress.rb', line 254 def description @description end |
#end_time ⇒ Time? (readonly)
Returns End time.
269 270 271 |
# File 'lib/rich/progress.rb', line 269 def end_time @end_time end |
#finished ⇒ Boolean (readonly)
Returns Task is finished.
263 264 265 |
# File 'lib/rich/progress.rb', line 263 def finished @finished end |
#start_time ⇒ Time (readonly)
Returns Start time.
266 267 268 |
# File 'lib/rich/progress.rb', line 266 def start_time @start_time end |
#total ⇒ Integer (readonly)
Returns Total steps.
257 258 259 |
# File 'lib/rich/progress.rb', line 257 def total @total end |
Instance Method Details
#advance(steps = 1) ⇒ Object
Update progress
282 283 284 285 |
# File 'lib/rich/progress.rb', line 282 def advance(steps = 1) @completed = [@completed + steps, @total].min finish if @completed >= @total end |
#elapsed ⇒ Float?
Returns Elapsed time.
306 307 308 |
# File 'lib/rich/progress.rb', line 306 def elapsed (@end_time || Time.now) - @start_time end |
#finish ⇒ Object
Mark as finished
295 296 297 298 |
# File 'lib/rich/progress.rb', line 295 def finish @finished = true @end_time = Time.now end |
#progress ⇒ Float
Returns Progress fraction.
301 302 303 |
# File 'lib/rich/progress.rb', line 301 def progress @completed.to_f / @total end |
#update(value) ⇒ Object
Set completed directly
289 290 291 292 |
# File 'lib/rich/progress.rb', line 289 def update(value) @completed = [[value, 0].max, @total].min finish if @completed >= @total end |