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_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 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
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?
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
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?
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?
102 103 104 |
# File 'lib/rubyfocus/items/task.rb', line 102 def has_subtasks? tasks.size > 0 end |
#immediate_tasks ⇒ Object
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_tasks ⇒ Object
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_task ⇒ Object
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_tasks ⇒ Object
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 |
#tasks ⇒ Object
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?
97 98 99 |
# File 'lib/rubyfocus/items/task.rb', line 97 def tasks_remain? tasks.any?{ |t| t.completed.nil? } end |
#to_project ⇒ Object
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 |