Module: Arachni::Mixins::ProgressBar
- Extended by:
- ProgressBar
- Included in:
- ProgressBar, UI::CLI
- 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/arachni/mixins/progress_bar.rb', line 40 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
23 24 25 26 27 28 29 |
# File 'lib/arachni/mixins/progress_bar.rb', line 23 def format_time( t ) t = t.to_i 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
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/arachni/mixins/progress_bar.rb', line 65 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 |