Class: Rubyfocus::Task
- Inherits:
-
RankedItem
- Object
- Item
- NamedItem
- RankedItem
- Rubyfocus::Task
- Includes:
- Parser
- Defined in:
- lib/rubyfocus/items/task.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#completed ⇒ Object
Inherits from RankedItem: * rank Inherits from NamedItem: * name Inherits from Item: * id * added * modified * document.
-
#due ⇒ Object
Inherits from RankedItem: * rank Inherits from NamedItem: * name Inherits from Item: * id * added * modified * document.
-
#flagged ⇒ Object
(also: #flagged?)
Inherits from RankedItem: * rank Inherits from NamedItem: * name Inherits from Item: * id * added * modified * document.
-
#note ⇒ Object
Inherits from RankedItem: * rank Inherits from NamedItem: * name Inherits from Item: * id * added * modified * document.
-
#order ⇒ Object
Inherits from RankedItem: * rank Inherits from NamedItem: * name Inherits from Item: * id * added * modified * document.
-
#start ⇒ Object
Inherits from RankedItem: * rank Inherits from NamedItem: * name Inherits from Item: * id * added * modified * document.
Attributes inherited from RankedItem
Attributes inherited from NamedItem
Attributes inherited from Item
#added, #document, #id, #modified
Class Method Summary collapse
Instance Method Summary collapse
-
#actionable_tasks ⇒ Object
A list of all tasks that you can take action on.
- #apply_xml(n) ⇒ Object
-
#blocked? ⇒ Boolean
Can we attack this task, or does its container stop that happening?.
-
#completed? ⇒ Boolean
Convenience methods.
-
#deferred? ⇒ Boolean
Can we only start this task at some point in the future?.
-
#has_subtasks? ⇒ Boolean
Does this task have any subtasks?.
-
#immediate_tasks ⇒ Object
Collect only immediate tasks: I don’t care about this subtasks malarky.
-
#incomplete_tasks ⇒ Object
A list of all tasks that aren’t complete.
-
#initialize(document, n = nil) ⇒ Task
constructor
A new instance of Task.
-
#next_available_immediate_task ⇒ Object
The first non-completed immediate child task.
-
#next_available_task ⇒ Object
The first non-completed task, determined by order.
-
#next_tasks ⇒ Object
A list of all tasks that are not blocked.
-
#tasks ⇒ Object
Collect all child tasks.
-
#tasks_remain? ⇒ Boolean
Are there any tasks on this project which aren’t completed?.
-
#to_project ⇒ Object
Convert the task to a project.
Methods included from Parser
Methods inherited from RankedItem
Methods inherited from NamedItem
Methods inherited from Item
Methods included from ConditionalExec
Methods included from IDRef
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
#completed ⇒ Object
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 |
#due ⇒ Object
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 |
#flagged ⇒ Object 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 |
#note ⇒ Object
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 |
#order ⇒ Object
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 |
#start ⇒ Object
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
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_tasks ⇒ Object
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?
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
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?
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?
111 112 113 |
# File 'lib/rubyfocus/items/task.rb', line 111 def has_subtasks? tasks.size > 0 end |
#immediate_tasks ⇒ Object
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_tasks ⇒ Object
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_task ⇒ Object
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_task ⇒ Object
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_tasks ⇒ Object
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 |
#tasks ⇒ Object
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?
106 107 108 |
# File 'lib/rubyfocus/items/task.rb', line 106 def tasks_remain? tasks.any?{ |t| t.completed.nil? } end |
#to_project ⇒ Object
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 |