Class: Woodhouse::Progress::StatusTicker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job, name, keyw = {}) ⇒ StatusTicker

Returns a new instance of StatusTicker.



88
89
90
91
92
93
94
# File 'lib/woodhouse/extensions/progress.rb', line 88

def initialize(job, name, keyw = {})
  self.job  = job
  self.name = name
  self.top  = keyw[:top]
  self.current = keyw.fetch(:start, 0)
  self.status = keyw[:status]
end

Instance Attribute Details

#currentObject

Returns the value of attribute current.



85
86
87
# File 'lib/woodhouse/extensions/progress.rb', line 85

def current
  @current
end

#statusObject

Returns the value of attribute status.



86
87
88
# File 'lib/woodhouse/extensions/progress.rb', line 86

def status
  @status
end

#topObject

Returns the value of attribute top.



84
85
86
# File 'lib/woodhouse/extensions/progress.rb', line 84

def top
  @top
end

Instance Method Details

#count_attributesObject



100
101
102
103
104
# File 'lib/woodhouse/extensions/progress.rb', line 100

def count_attributes
  { "current" => current }.tap do |h|
    h["top"] = top if top
  end
end

#tick(keyw = {}) ⇒ Object Also known as: call



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/woodhouse/extensions/progress.rb', line 106

def tick(keyw = {})
  status = keyw[:status]
  count  = keyw[:count]
  by     = keyw[:by] || 1
  new_top = keyw[:top]

  if status
    self.status = status
  end
  
  if current
    next_tick = count || current + by

    self.current = next_tick
  end

  self.top = new_top if new_top
   
  job.update_progress(to_hash)
end

#to_hashObject



96
97
98
# File 'lib/woodhouse/extensions/progress.rb', line 96

def to_hash
  { name => count_attributes.merge( "status" => status ) }
end