Class: ActionItem

Inherits:
Object
  • Object
show all
Includes:
RecordHelper
Defined in:
lib/startask.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RecordHelper

#generate_id, #logit

Constructor Details

#initialize(s, callback = nil, id: nil) ⇒ ActionItem

Returns a new instance of ActionItem.



28
29
30
31
32
33
34
35
# File 'lib/startask.rb', line 28

def initialize(s, callback=nil, id: nil)
  
  @id = id || generate_id()
  @title = s
  @log = []
  @callback = callback
  
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



26
27
28
# File 'lib/startask.rb', line 26

def id
  @id
end

Instance Method Details

#doneObject Also known as: completed



37
38
39
# File 'lib/startask.rb', line 37

def done()
  logaction :completed
end

#find(id) ⇒ Object



43
44
45
# File 'lib/startask.rb', line 43

def find(id)
  return self if id == @id
end

#log(detail: false) ⇒ Object



47
48
49
# File 'lib/startask.rb', line 47

def log(detail: false)
  detail ? @log.map {|x| [@id, x[-1], x[0], @title]} : @log
end

#logupdate(item) ⇒ Object



51
52
53
# File 'lib/startask.rb', line 51

def logupdate(item)
  @log << item
end

#startedObject



59
60
61
# File 'lib/startask.rb', line 59

def started()
  logaction :started
end

#statusObject



63
64
65
# File 'lib/startask.rb', line 63

def status()
  @log.last ? @log.last : []
end

#status=(status) ⇒ Object



71
72
73
74
75
76
77
78
79
80
# File 'lib/startask.rb', line 71

def status=(status)
  
  case status
  when :done
    done()
  when :started
    started()
  end
  
end

#stoppedObject



67
68
69
# File 'lib/startask.rb', line 67

def stopped()
  logaction :stopped
end

#to_sObject



55
56
57
# File 'lib/startask.rb', line 55

def to_s()
  @title
end

#to_xmlObject



82
83
84
85
86
87
# File 'lib/startask.rb', line 82

def to_xml()
  
  h = {id: @id, status: status().join(' ')}
  Rexle::Element.new(:action, attributes: h, value: @title)
  
end