Class: Evilution::Reporter::ProgressBar Private

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/reporter/progress_bar.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total:, output: $stdout, width: 30) ⇒ ProgressBar

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

#completedObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/evilution/reporter/progress_bar.rb', line 6

def completed
  @completed
end

#killedObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/evilution/reporter/progress_bar.rb', line 6

def killed
  @killed
end

#survivedObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/evilution/reporter/progress_bar.rb', line 6

def survived
  @survived
end

#totalObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/evilution/reporter/progress_bar.rb', line 6

def total
  @total
end

#widthObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
7
8
# File 'lib/evilution/reporter/progress_bar.rb', line 6

def width
  @width
end

Class Method Details

.tty?(io) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (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

#finishObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
# File 'lib/evilution/reporter/progress_bar.rb', line 35

def finish
  render
  @output.print("\n") if @tty
end

#renderObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
29
30
31
32
33
# File 'lib/evilution/reporter/progress_bar.rb', line 26

def render
  line = "#{bar_string} #{stats_string} | #{time_string}"
  if @tty
    @output.print("\r#{line}")
  else
    @output.puts(line)
  end
end

#tick(status:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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