Class: EnhanceSwarm::ProgressTracker
- Inherits:
-
Object
- Object
- EnhanceSwarm::ProgressTracker
- Defined in:
- lib/enhance_swarm/progress_tracker.rb
Instance Attribute Summary collapse
-
#current_step ⇒ Object
readonly
Returns the value of attribute current_step.
-
#estimated_tokens ⇒ Object
readonly
Returns the value of attribute estimated_tokens.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#total_steps ⇒ Object
readonly
Returns the value of attribute total_steps.
-
#used_tokens ⇒ Object
readonly
Returns the value of attribute used_tokens.
Instance Method Summary collapse
- #add_tokens(count) ⇒ Object
- #advance(steps = 1, message: nil, details: {}) ⇒ Object
- #complete(message: 'Completed!') ⇒ Object
- #fail(message: 'Failed!') ⇒ Object
-
#initialize(total_steps: 100, estimated_tokens: nil) ⇒ ProgressTracker
constructor
A new instance of ProgressTracker.
- #set_progress(step, message: nil, details: {}) ⇒ Object
- #update_status(message, details: {}) ⇒ Object
Constructor Details
#initialize(total_steps: 100, estimated_tokens: nil) ⇒ ProgressTracker
Returns a new instance of ProgressTracker.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 9 def initialize(total_steps: 100, estimated_tokens: nil) @total_steps = total_steps @current_step = 0 @start_time = Time.now @estimated_tokens = estimated_tokens @used_tokens = 0 @last_update = Time.now @status_message = 'Initializing...' @details = {} @spinner_chars = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] @spinner_index = 0 end |
Instance Attribute Details
#current_step ⇒ Object (readonly)
Returns the value of attribute current_step.
7 8 9 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 7 def current_step @current_step end |
#estimated_tokens ⇒ Object (readonly)
Returns the value of attribute estimated_tokens.
7 8 9 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 7 def estimated_tokens @estimated_tokens end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 7 def start_time @start_time end |
#total_steps ⇒ Object (readonly)
Returns the value of attribute total_steps.
7 8 9 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 7 def total_steps @total_steps end |
#used_tokens ⇒ Object (readonly)
Returns the value of attribute used_tokens.
7 8 9 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 7 def used_tokens @used_tokens end |
Instance Method Details
#add_tokens(count) ⇒ Object
36 37 38 39 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 36 def add_tokens(count) @used_tokens += count update_display end |
#advance(steps = 1, message: nil, details: {}) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 22 def advance(steps = 1, message: nil, details: {}) @current_step = [@current_step + steps, @total_steps].min @status_message = if @details.merge!(details) update_display end |
#complete(message: 'Completed!') ⇒ Object
47 48 49 50 51 52 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 47 def complete(message: 'Completed!') @current_step = @total_steps @status_message = update_display puts # Final newline end |
#fail(message: 'Failed!') ⇒ Object
54 55 56 57 58 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 54 def fail(message: 'Failed!') @status_message = update_display puts # Final newline end |
#set_progress(step, message: nil, details: {}) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 29 def set_progress(step, message: nil, details: {}) @current_step = [step, @total_steps].min @status_message = if @details.merge!(details) update_display end |
#update_status(message, details: {}) ⇒ Object
41 42 43 44 45 |
# File 'lib/enhance_swarm/progress_tracker.rb', line 41 def update_status(, details: {}) @status_message = @details.merge!(details) update_display end |