Class: Squealer::ProgressBar

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

Constant Summary collapse

@@progress_bar =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total) ⇒ ProgressBar

Returns a new instance of ProgressBar.



14
15
16
17
18
19
20
# File 'lib/squealer/progress_bar.rb', line 14

def initialize(total)
  @total = total
  @ticks = 0

  @progress_bar_width = 50
  @count_width = total.to_s.size
end

Class Method Details

.new(*args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/squealer/progress_bar.rb', line 6

def self.new(*args)
  if @@progress_bar
    nil
  else
    @@progress_bar = super
  end
end

Instance Method Details

#finishObject



28
29
30
31
32
# File 'lib/squealer/progress_bar.rb', line 28

def finish
  @end_time = clock
  @emitter.wakeup.join if @emitter
  @@progress_bar = nil
end

#startObject



22
23
24
25
26
# File 'lib/squealer/progress_bar.rb', line 22

def start
  @start_time = clock
  @emitter = start_emitter if total > 0
  self
end

#tickObject



34
35
36
# File 'lib/squealer/progress_bar.rb', line 34

def tick
  @ticks += 1
end