Class: Evilution::Reporter::ProgressBar
- Inherits:
-
Object
- Object
- Evilution::Reporter::ProgressBar
- Defined in:
- lib/evilution/reporter/progress_bar.rb
Instance Attribute Summary collapse
-
#completed ⇒ Object
readonly
Returns the value of attribute completed.
-
#killed ⇒ Object
readonly
Returns the value of attribute killed.
-
#survived ⇒ Object
readonly
Returns the value of attribute survived.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize(total:, output: $stdout, width: 30) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #render ⇒ Object
- #tick(status:) ⇒ Object
Constructor Details
#initialize(total:, output: $stdout, width: 30) ⇒ ProgressBar
Returns a new instance of ProgressBar.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/evilution/reporter/progress_bar.rb', line 8 def initialize(total:, output: $stdout, width: 30) @total = total @output = output @width = width @completed = 0 @killed = 0 @survived = 0 @tty = self.class.tty?(output) @start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
Instance Attribute Details
#completed ⇒ Object (readonly)
Returns the value of attribute completed.
6 7 8 |
# File 'lib/evilution/reporter/progress_bar.rb', line 6 def completed @completed end |
#killed ⇒ Object (readonly)
Returns the value of attribute killed.
6 7 8 |
# File 'lib/evilution/reporter/progress_bar.rb', line 6 def killed @killed end |
#survived ⇒ Object (readonly)
Returns the value of attribute survived.
6 7 8 |
# File 'lib/evilution/reporter/progress_bar.rb', line 6 def survived @survived end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
6 7 8 |
# File 'lib/evilution/reporter/progress_bar.rb', line 6 def total @total end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
6 7 8 |
# File 'lib/evilution/reporter/progress_bar.rb', line 6 def width @width end |
Class Method Details
.tty?(io) ⇒ Boolean
40 41 42 |
# File 'lib/evilution/reporter/progress_bar.rb', line 40 def self.tty?(io) io.respond_to?(:tty?) && io.tty? end |
Instance Method Details
#finish ⇒ Object
35 36 37 38 |
# File 'lib/evilution/reporter/progress_bar.rb', line 35 def finish render @output.print("\n") if @tty end |
#render ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/evilution/reporter/progress_bar.rb', line 26 def render line = "#{} #{stats_string} | #{time_string}" if @tty @output.print("\r#{line}") else @output.puts(line) end end |
#tick(status:) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/evilution/reporter/progress_bar.rb', line 19 def tick(status:) @completed += 1 @killed += 1 if status == :killed @survived += 1 if status == :survived render end |