Class: BeamUp::Progress

Inherits:
Object
  • Object
show all
Defined in:
lib/beam_up/progress.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProgress

Returns a new instance of Progress.



5
6
7
8
9
10
11
# File 'lib/beam_up/progress.rb', line 5

def initialize
  @mutex = Thread::Mutex.new
  @current = 0
  @total = nil
  @type = nil
  @spinner_index = 0
end

Instance Attribute Details

#currentObject (readonly)

Returns the value of attribute current.



12
13
14
# File 'lib/beam_up/progress.rb', line 12

def current
  @current
end

#totalObject (readonly)

Returns the value of attribute total.



12
13
14
# File 'lib/beam_up/progress.rb', line 12

def total
  @total
end

#typeObject (readonly)

Returns the value of attribute type.



12
13
14
# File 'lib/beam_up/progress.rb', line 12

def type
  @type
end

Instance Method Details

#finishObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/beam_up/progress.rb', line 33

def finish
  @mutex.synchronize do
    return if @total.nil?

    stop_render

    @total = nil
    @current = nil
    @type = nil
  end
end

#start(type:, total:) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/beam_up/progress.rb', line 14

def start(type:, total:)
  @mutex.synchronize do
    @type = type
    @total = total
    @current = 0
    @spinner_index = 0

    render
  end
end

#tick(bytes: nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/beam_up/progress.rb', line 25

def tick(bytes: nil)
  @mutex.synchronize do
    @current += (@type == :bytes) ? bytes.to_i : 1

    render
  end
end