class Aaron::Task
Attributes
block[R]
range[R]
Public Class Methods
new(range, proc = nil, &block)
click to toggle source
# File lib/aaron/task.rb, line 7 def initialize range, proc = nil, &block @range = range @block = proc or block end
Public Instance Methods
apply_time!(time)
click to toggle source
# 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()
click to toggle source
# File lib/aaron/task.rb, line 12 def next_sleep @next_sleep ||= get_next_sleep end
ready_to_trigger?()
click to toggle source
# File lib/aaron/task.rb, line 23 def ready_to_trigger? @next_sleep.nil? end
trigger()
click to toggle source
# File lib/aaron/task.rb, line 27 def trigger if block.type then self.send(block.type) else block.call end end
Protected Instance Methods
exec()
click to toggle source
# File lib/aaron/task.rb, line 41 def exec cmd = block.call.split(' ') bin = File.expand_path(cmd[0]) if not File.exists?(bin) bin = cmd[0] end rest = cmd.drop(1).join(' ') bin += ' ' + rest `#{bin}` end
get_next_sleep()
click to toggle source
# File lib/aaron/task.rb, line 33 def get_next_sleep if range.instance_of?(Range) rand(range) else range end end