Class: Termtter::Task

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}, &block) ⇒ Task

Returns a new instance of Task.



6
7
8
9
10
11
12
# File 'lib/termtter/task.rb', line 6

def initialize(args = {}, &block)
  @name = args[:name]
  @exec_at = Time.now + (args[:after] || 0)
  @interval = args[:interval]
  @exec_proc = block || lambda {}
  @work = true
end

Instance Attribute Details

#exec_atObject

Returns the value of attribute exec_at.



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

def exec_at
  @exec_at
end

#exec_procObject

Returns the value of attribute exec_proc.



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

def exec_proc
  @exec_proc
end

#intervalObject

Returns the value of attribute interval.



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

def interval
  @interval
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#workObject

Returns the value of attribute work.



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

def work
  @work
end

Instance Method Details

#executeObject



13
14
15
16
# File 'lib/termtter/task.rb', line 13

def execute
  args = if exec_proc.arity.zero? then [] else [self] end
  exec_proc.call(*args) if work
end