Class: Dalliance::ProgressMeter

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/dalliance/progress_meter.rb

Instance Method Summary collapse

Instance Method Details

#current_countObject



16
17
18
# File 'lib/dalliance/progress_meter.rb', line 16

def current_count
  self[:current_count] ||= 0
end

#increment!Object



61
62
63
# File 'lib/dalliance/progress_meter.rb', line 61

def increment!
  Dalliance::ProgressMeter.increment_counter(:current_count, self.id)
end

#progressObject

TODO: This is just a stopgap until I fix increment! to be thread-safe



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/dalliance/progress_meter.rb', line 47

def progress
  begin
    _progress = (current_count.to_f / total_count.to_f * 100).to_i

    #Handle an incorrect total_count...
    _progress = 100 if _progress > 100
  rescue
    #what, are you diving by zero?
    _progress = 0
  end

  _progress
end

#total_countObject



20
21
22
# File 'lib/dalliance/progress_meter.rb', line 20

def total_count
  self[:total_count] ||= 1
end

#total_count=(count) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/dalliance/progress_meter.rb', line 24

def total_count=(count)
  if count <= 0
    self[:total_count] = 1
  else
    self[:total_count] = count
  end
end