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



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

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
38
39
40
41
# File 'lib/rubyfocus/items/task.rb', line 26

def apply_xml(n)
	super(n)

	t = n.at_xpath("xmlns:task")
	f = n.at_xpath("xmlns:project/xmlns:folder")

	conditional_set(:container_id, (t && t["idref"]) || (f && f["idref"])){ |e| e }

	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)


121
122
123
124
125
126
127
128
129
130
# File 'lib/rubyfocus/items/task.rb', line 121

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)


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

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

#deferred?Boolean

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

Returns:

  • (Boolean)


116
117
118
# File 'lib/rubyfocus/items/task.rb', line 116

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

#has_subtasks?Boolean

Does this task have any subtasks?

Returns:

  • (Boolean)


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

def has_subtasks?
	tasks.size > 0
end

#immediate_tasksObject

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



67
68
69
# File 'lib/rubyfocus/items/task.rb', line 67

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

#incomplete_tasksObject

A list of all tasks that aren’t complete



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

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

#next_available_immediate_taskObject

The first non-completed immediate child task



82
83
84
# File 'lib/rubyfocus/items/task.rb', line 82

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



72
73
74
75
76
77
78
79
# File 'lib/rubyfocus/items/task.rb', line 72

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.



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

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.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rubyfocus/items/task.rb', line 48

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)


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

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

#to_projectObject

Convert the task to a project. Does not supply a document, as this would overwrite current task



136
137
138
139
140
141
142
143
144
# File 'lib/rubyfocus/items/task.rb', line 136

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