Class: Rubyfocus::Task

Inherits:
RankedItem show all
Includes:
Parser
Defined in:
lib/rubyfocus/items/task.rb

Direct Known Subclasses

Project

Instance Attribute Summary collapse

Attributes inherited from RankedItem

#rank

Attributes inherited from NamedItem

#name

Attributes inherited from Item

#added, #document, #id, #modified

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Parser

included, parse

Methods inherited from RankedItem

#ancestry, #contained_within?

Methods inherited from NamedItem

#to_s

Methods inherited from Item

#inspect, #to_serial

Methods included from ConditionalExec

#conditional_set

Methods included from IDRef

included

Constructor Details

#initialize(document, n = nil) ⇒ Task

Returns a new instance of Task.



20
21
22
23
24
# File 'lib/rubyfocus/items/task.rb', line 20

def initialize(document, n=nil)
  @order = :sequential
  @flagged = false
  super(document,n)
end

Instance Attribute Details

#completedObject

Inherits from RankedItem:

  • rank

Inherits from NamedItem:

  • name

Inherits from Item:

  • id

  • added

  • modified

  • document



17
18
19
# File 'lib/rubyfocus/items/task.rb', line 17

def completed
  @completed
end

#dueObject

Inherits from RankedItem:

  • rank

Inherits from NamedItem:

  • name

Inherits from Item:

  • id

  • added

  • modified

  • document



17
18
19
# File 'lib/rubyfocus/items/task.rb', line 17

def due
  @due
end

#flaggedObject Also known as: flagged?

Inherits from RankedItem:

  • rank

Inherits from NamedItem:

  • name

Inherits from Item:

  • id

  • added

  • modified

  • document



17
18
19
# File 'lib/rubyfocus/items/task.rb', line 17

def flagged
  @flagged
end

#noteObject

Inherits from RankedItem:

  • rank

Inherits from NamedItem:

  • name

Inherits from Item:

  • id

  • added

  • modified

  • document



17
18
19
# File 'lib/rubyfocus/items/task.rb', line 17

def note
  @note
end

#orderObject

Inherits from RankedItem:

  • rank

Inherits from NamedItem:

  • name

Inherits from Item:

  • id

  • added

  • modified

  • document



17
18
19
# File 'lib/rubyfocus/items/task.rb', line 17

def order
  @order
end

#startObject

Inherits from RankedItem:

  • rank

Inherits from NamedItem:

  • name

Inherits from Item:

  • id

  • added

  • modified

  • document



17
18
19
# File 'lib/rubyfocus/items/task.rb', line 17

def start
  @start
end

Class Method Details

.matches_node?(node) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/rubyfocus/items/task.rb', line 3

def self.matches_node?(node)
  return (node.name == "task")
end

Instance Method Details

#actionable_tasksObject

A list of all tasks that you can take action on. Actionable tasks are tasks that are:

  • not completed

  • not blocked (as part of a sequential project or task group)

  • not due to start in the future



87
88
89
# File 'lib/rubyfocus/items/task.rb', line 87

def actionable_tasks
  next_tasks.select{ |t| !t.deferred? }
end

#apply_xml(n) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rubyfocus/items/task.rb', line 26

def apply_xml(n)
  super(n)
  conditional_set(:container_id, n.at_xpath("xmlns:task") || n.at_xpath("xmlns:project/xmlns:folder")){ |e| e["idref"] }

  conditional_set(:context_id,   n.at_xpath("xmlns:context")) { |e| e["idref"] }
  conditional_set(:note,         n.at_xpath("xmlns:note"))     { |e| e.inner_html.strip }
  conditional_set(:order,      n.at_xpath("xmlns:order"))    { |e| e.inner_html.to_sym }
  conditional_set(:flagged,      n.at_xpath("xmlns:flagged")) { |e| e.inner_html == "true" }
  conditional_set(:start,      n.at_xpath("xmlns:start"))    { |e| Time.safely_parse(e.inner_html) }
  conditional_set(:due,         n.at_xpath("xmlns:due"))      { |e| Time.safely_parse(e.inner_html) }
  conditional_set(:completed,    n.at_xpath("xmlns:completed")){ |e| Time.safely_parse(e.inner_html) }
end

#blocked?Boolean

Can we attack this task, or does its container stop that happening?

Returns:

  • (Boolean)


117
118
119
120
121
122
123
124
125
126
# File 'lib/rubyfocus/items/task.rb', line 117

def blocked?
  # Cannot be blocked without a container, or when inside a folder
  return false if container.nil? || container.is_a?(Rubyfocus::Folder)

  # If container is blocked, I must be blocked
  return true if container.blocked?

  # Otherwise, only blocked if the container is sequential and I'm not next
  return (container.order == :sequential && container.next_available_immediate_task != self)
end

#completed?Boolean

Convenience methods

Returns:

  • (Boolean)


40
# File 'lib/rubyfocus/items/task.rb', line 40

def completed?; !self.completed.nil?; end

#deferred?Boolean

Can we only start this task at some point in the future?

Returns:

  • (Boolean)


112
113
114
# File 'lib/rubyfocus/items/task.rb', line 112

def deferred?
  start && start > Time.now
end

#has_subtasks?Boolean

Does this task have any subtasks?

Returns:

  • (Boolean)


107
108
109
# File 'lib/rubyfocus/items/task.rb', line 107

def has_subtasks?
  tasks.size > 0
end

#immediate_tasksObject

Collect only immediate tasks: I don’t care about this subtasks malarky



63
64
65
# File 'lib/rubyfocus/items/task.rb', line 63

def immediate_tasks
  document.tasks.select(container_id: self.id)
end

#incomplete_tasksObject

A list of all tasks that aren’t complete



97
98
99
# File 'lib/rubyfocus/items/task.rb', line 97

def incomplete_tasks
  tasks.select{ |t| !t.completed? }
end

#next_available_immediate_taskObject

The first non-completed immediate child task



78
79
80
# File 'lib/rubyfocus/items/task.rb', line 78

def next_available_immediate_task
  immediate_tasks.select{ |t| !t.completed? }.sort_by(&:rank).first
end

#next_available_taskObject

The first non-completed task, determined by order



68
69
70
71
72
73
74
75
# File 'lib/rubyfocus/items/task.rb', line 68

def next_available_task
  nat_candidate = next_available_immediate_task
  if nat_candidate && nat_candidate.has_subtasks?
    nat_candidate.next_available_task
  else
    nat_candidate
  end
end

#next_tasksObject

A list of all tasks that are not blocked.



92
93
94
# File 'lib/rubyfocus/items/task.rb', line 92

def next_tasks
  incomplete_tasks.select{ |t| !t.blocked? }
end

#tasksObject

Collect all child tasks. If child tasks have their own subtasks, will instead fetch those.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/rubyfocus/items/task.rb', line 44

def tasks
  @tasks ||= if self.id.nil?
    []
  else
    t_arr = document.tasks.select(container_id: self.id)
    i = 0
    while i < t_arr.size
      task = t_arr[i]
      if task.has_subtasks?
        t_arr += t_arr.delete_at(i).tasks
      else
        i += 1
      end
    end
    t_arr
  end
end

#tasks_remain?Boolean

Are there any tasks on this project which aren’t completed?

Returns:

  • (Boolean)


102
103
104
# File 'lib/rubyfocus/items/task.rb', line 102

def tasks_remain?
  tasks.any?{ |t| t.completed.nil? }
end

#to_projectObject

Convert the task to a project



132
133
134
135
136
137
138
139
# File 'lib/rubyfocus/items/task.rb', line 132

def to_project
  p = Rubyfocus::Project.new(self.document)
  instance_variables.each do |ivar|
    setter = ivar.to_s.gsub(/^@/,"") + "="
    p.send(setter, self.instance_variable_get(ivar))  if p.respond_to?(setter)
  end
  p
end