Class: CloudEncryptedSync::ProgressMeter

Inherits:
Object
  • Object
show all
Defined in:
lib/cloud_encrypted_sync/progress_meter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_index, options = {}) {|_self| ... } ⇒ ProgressMeter

Returns a new instance of ProgressMeter.

Yields:

  • (_self)

Yield Parameters:



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

def initialize(max_index,options = {})
  @max_index = max_index.to_f
  @label = options[:label] || ''
  @completed_index = 0.0
  @start_time = Time.now
  yield self if block_given?
end

Instance Attribute Details

#completed_indexObject

Returns the value of attribute completed_index.



3
4
5
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 3

def completed_index
  @completed_index
end

#labelObject (readonly)

Returns the value of attribute label.



4
5
6
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 4

def label
  @label
end

#max_indexObject (readonly)

Returns the value of attribute max_index.



4
5
6
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 4

def max_index
  @max_index
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



4
5
6
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 4

def start_time
  @start_time
end

Instance Method Details

#estimated_finish_timeObject



18
19
20
21
22
23
24
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 18

def estimated_finish_time
  if percent_completed > 0
    start_time + ((100/percent_completed)*time_elapsed)
  else
    start_time + 3600
  end
end

#estimated_time_remainingObject



14
15
16
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 14

def estimated_time_remaining
  Time.at(estimated_finish_time - Time.now)
end

#increment_completed_index(amount = 1) ⇒ Object



34
35
36
37
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 34

def increment_completed_index(amount = 1)
  self.completed_index += amount
  notify
end

#percent_completedObject



26
27
28
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 26

def percent_completed
  (completed_index/max_index)*100
end

#time_elapsedObject



30
31
32
# File 'lib/cloud_encrypted_sync/progress_meter.rb', line 30

def time_elapsed
  Time.now - start_time
end