Class: RSpecLetAnalyzer::ProgressReporter
- Inherits:
-
Object
- Object
- RSpecLetAnalyzer::ProgressReporter
- Defined in:
- lib/rspec_let_analyzer/progress_reporter.rb
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(enabled) ⇒ ProgressReporter
constructor
A new instance of ProgressReporter.
- #update(current:, total:, file:) ⇒ Object
Constructor Details
#initialize(enabled) ⇒ ProgressReporter
Returns a new instance of ProgressReporter.
5 6 7 8 |
# File 'lib/rspec_let_analyzer/progress_reporter.rb', line 5 def initialize(enabled) @enabled = enabled @last_message_length = 0 end |
Instance Method Details
#clear ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/rspec_let_analyzer/progress_reporter.rb', line 24 def clear return unless @enabled # Clear the progress line completely print "\r#{' ' * @last_message_length}\r" $stdout.flush end |
#update(current:, total:, file:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rspec_let_analyzer/progress_reporter.rb', line 10 def update(current:, total:, file:) return unless @enabled percentage = (current.to_f / total * 100).round = format('[%3d%%] %s', percentage, file) # Clear previous line by overwriting with spaces, then print new message clear_length = [@last_message_length, .length].max print "\r#{' ' * clear_length}\r#{}" $stdout.flush @last_message_length = .length end |