Class: Evilution::Reporter::ProgressBar

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#completedObject (readonly)

Returns the value of attribute completed.



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

def completed
  @completed
end

#killedObject (readonly)

Returns the value of attribute killed.



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

def killed
  @killed
end

#survivedObject (readonly)

Returns the value of attribute survived.



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

def survived
  @survived
end

#totalObject (readonly)

Returns the value of attribute total.



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

def total
  @total
end

#widthObject (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

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



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

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

#renderObject



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



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