Class: Aaron::Task
- Inherits:
-
Object
- Object
- Aaron::Task
- Defined in:
- lib/aaron/task.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
- #apply_time!(time) ⇒ Object
-
#initialize(range, proc = nil, &block) ⇒ Task
constructor
A new instance of Task.
- #next_sleep ⇒ Object
- #ready_to_trigger? ⇒ Boolean
- #trigger ⇒ Object
Constructor Details
#initialize(range, proc = nil, &block) ⇒ Task
Returns a new instance of Task.
7 8 9 10 |
# File 'lib/aaron/task.rb', line 7 def initialize range, proc = nil, &block @range = range @block = proc or block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/aaron/task.rb', line 5 def block @block end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
5 6 7 |
# File 'lib/aaron/task.rb', line 5 def range @range end |
Instance Method Details
#apply_time!(time) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/aaron/task.rb', line 16 def apply_time! time @next_sleep -= time if @next_sleep == 0 @next_sleep = nil end end |
#next_sleep ⇒ Object
12 13 14 |
# File 'lib/aaron/task.rb', line 12 def next_sleep @next_sleep ||= get_next_sleep end |
#ready_to_trigger? ⇒ Boolean
23 24 25 |
# File 'lib/aaron/task.rb', line 23 def ready_to_trigger? @next_sleep.nil? end |
#trigger ⇒ Object
27 28 29 |
# File 'lib/aaron/task.rb', line 27 def trigger if block.type then self.send(block.type) else block.call end end |