Class: Aaron::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/aaron/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/aaron/task.rb', line 5

def block
  @block
end

#rangeObject (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_sleepObject



12
13
14
# File 'lib/aaron/task.rb', line 12

def next_sleep
  @next_sleep ||= get_next_sleep
end

#ready_to_trigger?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/aaron/task.rb', line 23

def ready_to_trigger?
  @next_sleep.nil?
end

#triggerObject



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