Class: StarTask

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

Overview

task dictionary


import (method) Imports a new “task” which includes a STAR document outline done (method) The task has been completed completed - alias of method done status (method) returns the most recent status from the task log log (attr) returns an Array object containing a timeline of status messages in chronological order progress (method) returns the most recent action completed or started duration (method) returns the actual duration type (attr) Frequency type e.g. (daily, weekly, monthly) estimate_duration (attr) OPTIONAL. the estimate duration is explicitly declared in the STAR document or is calculated from estimate durations in the actions if declared. actions (method) returns the Actions object location (attr) set or get the current physical location started (method) adds a status message to the log

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RecordHelper

#generate_id, #logit

Constructor Details

#initialize(src = nil, debug: false) ⇒ StarTask

Returns a new instance of StarTask.



218
219
220
221
222
223
224
225
# File 'lib/startask.rb', line 218

def initialize(src=nil, debug: false)
  
  @debug = debug
  @id = generate_id()
  @log = []
  @status = ''
  import src if src
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



216
217
218
# File 'lib/startask.rb', line 216

def actions
  @actions
end

#idObject (readonly)

Returns the value of attribute id.



216
217
218
# File 'lib/startask.rb', line 216

def id
  @id
end

#logObject (readonly)

Returns the value of attribute log.



216
217
218
# File 'lib/startask.rb', line 216

def log
  @log
end

#resultsObject (readonly)

Returns the value of attribute results.



216
217
218
# File 'lib/startask.rb', line 216

def results
  @results
end

#situationObject (readonly)

Returns the value of attribute situation.



216
217
218
# File 'lib/startask.rb', line 216

def situation
  @situation
end

#taskObject (readonly)

Returns the value of attribute task.



216
217
218
# File 'lib/startask.rb', line 216

def task
  @task
end

Instance Method Details

#doneObject Also known as: completed



227
228
229
# File 'lib/startask.rb', line 227

def done()
  logtask :completed
end

#import(raws) ⇒ Object



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/startask.rb', line 233

def import(raws)

  s, _ = RXFHelper.read raws
  puts 's: ' + s.inspect if @debug
  
  obj = if s.lstrip[0] == '#' then
  
    a = s.split(/^#+ /)
    a.shift
    
   rawh =  a.map do |x|
     
      rawlabel, body = x.split(/\n/,2)
      
      [rawlabel.rstrip.downcase.gsub(/\s+/, '_').to_sym, 
       body.strip.gsub(/^(\s*)[\*\+] /,'\1')]
      
    end.to_h
    
    h = {}
    h[:situation] = rawh[:situation]
    h[:task] = rawh[:task]
    h[:action] = {items: LineTree.new(rawh[:action]).to_a(normalize: true)}
    h[:result] = {items: LineTree.new(rawh[:result]).to_a(normalize: true)}
    h
    
  else
    s
  end
  
  puts 'obj: ' + obj.inspect if @debug
      
  kvx = Kvx.new obj
  @situation = kvx.situation
  @task = kvx.task
  @actions = Actions.new(self).import(kvx.action[:items])
  @results = Results.new(self).import(kvx.result[:items])

end

#startedObject

adds a status message to the log



275
276
277
# File 'lib/startask.rb', line 275

def started()
  logtask :started
end

#statusObject



279
280
281
# File 'lib/startask.rb', line 279

def status()
  @status
end

#status=(s) ⇒ Object



283
284
285
# File 'lib/startask.rb', line 283

def status=(s)
  @status = s
end

#stoppedObject



287
288
289
# File 'lib/startask.rb', line 287

def stopped()
  logtask :stopped
end

#to_xmlObject



291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/startask.rb', line 291

def to_xml()
  
  situation = Rexle::Element.new( :situation, value: @situation)
  task = Rexle::Element.new( :task, value: @task)
  
  doc = Rexle.new('<star/>')
  doc.root.add situation
  doc.root.add task
  doc.root.add @actions.to_xml
  doc.root.add @results.to_xml
  doc.root.xml pretty: true
  
end