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
21
# 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



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

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

#startObject



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

def start
  @start_time = Time.new
  @emitter = start_emitter if total > 0
  self
end

#tickObject



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

def tick
  @ticks += 1
end