Class: BeamUp::Progress
- Inherits:
-
Object
- Object
- BeamUp::Progress
- Defined in:
- lib/beam_up/progress.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #finish ⇒ Object
-
#initialize ⇒ Progress
constructor
A new instance of Progress.
- #start(type:, total:) ⇒ Object
- #tick(bytes: nil) ⇒ Object
Constructor Details
#initialize ⇒ Progress
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
#current ⇒ Object (readonly)
Returns the value of attribute current.
12 13 14 |
# File 'lib/beam_up/progress.rb', line 12 def current @current end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
12 13 14 |
# File 'lib/beam_up/progress.rb', line 12 def total @total end |
#type ⇒ Object (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
#finish ⇒ Object
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 |