Class: EnhanceSwarm::ProgressTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/enhance_swarm/progress_tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_stepObject (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_tokensObject (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_timeObject (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_stepsObject (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_tokensObject (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 = message if message
  @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 = 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 = 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 = message if message
  @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(message, details: {})
  @status_message = message
  @details.merge!(details)
  update_display
end