Module: Arachni::Mixins::ProgressBar
- Extended by:
- ProgressBar
- Included in:
- ProgressBar, UI::CLI::RPC::Instance, UI::CLI::Utilities
- Defined in:
- lib/arachni/mixins/progress_bar.rb
Overview
Progress bar and ETA methods
Instance Method Summary collapse
-
#eta(prog, start_time) ⇒ String
Calculates ETA (Estimated Time of Arrival) based on current progress and the start time of the operation.
-
#format_time(t) ⇒ Object
Formats elapsed time to hour:min:sec.
-
#progress_bar(progress, width = 100) ⇒ String
Returns an ASCII progress bar based on the current progress percentage.
Instance Method Details
#eta(prog, start_time) ⇒ String
Calculates ETA (Estimated Time of Arrival) based on current progress and the start time of the operation.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/arachni/mixins/progress_bar.rb', line 46 def eta( prog, start_time ) @last_prog ||= prog @last_eta ||= "--:--:--" if @last_prog != prog elapsed = Time.now - start_time eta = elapsed * 100 / prog - elapsed eta_str = format_time( eta ) else eta_str = @last_eta prog = @last_prog end @last_prog = prog @last_eta = eta_str end |
#format_time(t) ⇒ Object
Formats elapsed time to hour:min:sec
29 30 31 32 33 34 35 |
# File 'lib/arachni/mixins/progress_bar.rb', line 29 def format_time( t ) t = t.to_i rescue 0 sec = t % 60 min = ( t / 60 ) % 60 hour = t / 3600 sprintf( "%02d:%02d:%02d", hour, min, sec ) end |
#progress_bar(progress, width = 100) ⇒ String
Returns an ASCII progress bar based on the current progress percentage
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/arachni/mixins/progress_bar.rb', line 71 def ( progress, width = 100 ) progress = 100.0 if progress > 100 = progress * width / 100 = '=' * ( .ceil - 1 ).abs + '>' pad = ( width - ) += ' ' * pad if pad > 0 "#{progress}% [#{}] 100% " end |