Class: Sus::Output::Progress
- Inherits:
-
Object
- Object
- Sus::Output::Progress
- Defined in:
- lib/sus/output/progress.rb
Overview
Represents a progress tracker for test execution.
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
- #The current progress value.(currentprogressvalue.) ⇒ Object readonly
- #The total value.(totalvalue.) ⇒ Object readonly
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
-
.now ⇒ Object
Get the current monotonic time.
Instance Method Summary collapse
- #average_duration ⇒ Object
-
#clear ⇒ Object
Clear the progress display.
- #duration ⇒ Object
- #estimated_remaining_time ⇒ Object
-
#expand(amount = 1) ⇒ Object
Increase the total size of the progress.
-
#increment(amount = 1) ⇒ Object
Increase the amount of work done.
-
#initialize(output, total = 0, minimum_output_duration: 1.0) ⇒ Progress
constructor
Initialize a new Progress tracker.
- #progress ⇒ Object
- #remaining ⇒ Object
-
#report(index, context, state) ⇒ Object
Report the status of a specific item.
- #The subject being tracked.=(subjectbeingtracked. = (value)) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(output, total = 0, minimum_output_duration: 1.0) ⇒ Progress
Initialize a new Progress tracker.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sus/output/progress.rb', line 24 def initialize(output, total = 0, minimum_output_duration: 1.0) @output = output @subject = subject @start_time = Progress.now if @output.interactive? @bar = Bar.new @lines = Lines.new(@output) @lines[0] = @bar end @current = 0 @total = total end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
44 45 46 |
# File 'lib/sus/output/progress.rb', line 44 def current @current end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
41 42 43 |
# File 'lib/sus/output/progress.rb', line 41 def subject @subject end |
#The current progress value.(currentprogressvalue.) ⇒ Object (readonly)
44 |
# File 'lib/sus/output/progress.rb', line 44 attr :current |
#The total value.(totalvalue.) ⇒ Object (readonly)
47 |
# File 'lib/sus/output/progress.rb', line 47 attr :total |
#total ⇒ Object (readonly)
Returns the value of attribute total.
47 48 49 |
# File 'lib/sus/output/progress.rb', line 47 def total @total end |
Class Method Details
.now ⇒ Object
Get the current monotonic time.
16 17 18 |
# File 'lib/sus/output/progress.rb', line 16 def self.now ::Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
Instance Method Details
#average_duration ⇒ Object
65 66 67 68 69 |
# File 'lib/sus/output/progress.rb', line 65 def average_duration if @current > 0 duration / @current end end |
#clear ⇒ Object
Clear the progress display.
114 115 116 |
# File 'lib/sus/output/progress.rb', line 114 def clear @lines&.clear end |
#duration ⇒ Object
50 51 52 |
# File 'lib/sus/output/progress.rb', line 50 def duration Progress.now - @start_time end |
#estimated_remaining_time ⇒ Object
72 73 74 75 76 |
# File 'lib/sus/output/progress.rb', line 72 def estimated_remaining_time if average_duration = self.average_duration average_duration * remaining end end |
#expand(amount = 1) ⇒ Object
Increase the total size of the progress.
93 94 95 96 97 98 99 100 |
# File 'lib/sus/output/progress.rb', line 93 def (amount = 1) @total += amount @bar&.update(@current, @total, self.to_s) @lines&.redraw(0) return self end |
#increment(amount = 1) ⇒ Object
Increase the amount of work done.
81 82 83 84 85 86 87 88 |
# File 'lib/sus/output/progress.rb', line 81 def increment(amount = 1) @current += amount @bar&.update(@current, @total, self.to_s) @lines&.redraw(0) return self end |
#progress ⇒ Object
55 56 57 |
# File 'lib/sus/output/progress.rb', line 55 def progress @current.to_f / @total.to_f end |
#remaining ⇒ Object
60 61 62 |
# File 'lib/sus/output/progress.rb', line 60 def remaining @total - @current end |
#report(index, context, state) ⇒ Object
Report the status of a specific item.
107 108 109 110 111 |
# File 'lib/sus/output/progress.rb', line 107 def report(index, context, state) @lines&.[]=(index+1, Status.new(state, context)) return self end |
#The subject being tracked.=(subjectbeingtracked. = (value)) ⇒ Object
41 |
# File 'lib/sus/output/progress.rb', line 41 attr :subject |
#to_s ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/sus/output/progress.rb', line 119 def to_s if estimated_remaining_time = self.estimated_remaining_time "#{@current}/#{@total} completed in #{formatted_duration(self.duration)}, #{formatted_duration(estimated_remaining_time)} remaining" else "#{@current}/#{@total} completed" end end |