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 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



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

def actionable_tasks
	@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.parse(e.inner_html) }
	conditional_set(:due, 		 		n.at_xpath("xmlns:due"))			{ |e| Time.parse(e.inner_html) }
	conditional_set(:completed,		n.at_xpath("xmlns:completed")){ |e| Time.parse(e.inner_html) }
end

#blocked?Boolean

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

Returns:

  • (Boolean)


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

def blocked?
	container && (container.order == :sequential) && (container.next_available_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)


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

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

#has_subtasks?Boolean

Does this task have any subtasks?

Returns:

  • (Boolean)


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

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



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

def incomplete_tasks
	@incomplete_tasks ||= tasks.select{ |t| !t.completed? }
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 = immediate_tasks.select{ |t| !t.completed? }.sort_by(&:rank).first
	if 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.



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

def next_tasks
	@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)


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

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

#to_projectObject

Convert the task to a project



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

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