Class: Woodhouse::Progress::StatusTicker
- Inherits:
-
Object
- Object
- Woodhouse::Progress::StatusTicker
- Defined in:
- lib/woodhouse/extensions/progress.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#status ⇒ Object
Returns the value of attribute status.
-
#top ⇒ Object
Returns the value of attribute top.
Instance Method Summary collapse
- #count_attributes ⇒ Object
-
#initialize(job, name, keyw = {}) ⇒ StatusTicker
constructor
A new instance of StatusTicker.
- #tick(keyw = {}) ⇒ Object (also: #call)
- #to_hash ⇒ Object
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
#current ⇒ Object
Returns the value of attribute current.
85 86 87 |
# File 'lib/woodhouse/extensions/progress.rb', line 85 def current @current end |
#status ⇒ Object
Returns the value of attribute status.
86 87 88 |
# File 'lib/woodhouse/extensions/progress.rb', line 86 def status @status end |
#top ⇒ Object
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_attributes ⇒ Object
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_hash ⇒ Object
96 97 98 |
# File 'lib/woodhouse/extensions/progress.rb', line 96 def to_hash { name => count_attributes.merge( "status" => status ) } end |