Class: Rubyfocus::Project

Inherits:
Task show all
Includes:
Parser
Defined in:
lib/rubyfocus/items/project.rb

Overview

The project represents an OmniFocus project object.

Instance Attribute Summary collapse

Attributes inherited from Task

#completed, #due, #flagged, #note, #order, #start

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 Task

#actionable_tasks, #blocked?, #deferred?, #has_subtasks?, #immediate_tasks, #incomplete_tasks, #next_available_immediate_task, #next_available_task, #next_tasks, #tasks, #tasks_remain?, #to_project

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 = nil, n = nil) ⇒ Project

Initialize the project with a document and optional node to base it off of. Also sets default values



32
33
34
35
36
37
# File 'lib/rubyfocus/items/project.rb', line 32

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

Instance Attribute Details

#last_reviewObject

When did we last review the project?



24
25
26
# File 'lib/rubyfocus/items/project.rb', line 24

def last_review
  @last_review
end

#review_intervalObject

How often to we review this project?



21
22
23
# File 'lib/rubyfocus/items/project.rb', line 21

def review_interval
  @review_interval
end

#singletonObject Also known as: singleton?

Singleton: contains one-off tasks



18
19
20
# File 'lib/rubyfocus/items/project.rb', line 18

def singleton
  @singleton
end

#statusObject

What’s the status of the project? Valid options: :active, :inactive, :done. Default is :active



28
29
30
# File 'lib/rubyfocus/items/project.rb', line 28

def status
  @status
end

Class Method Details

.matches_node?(node) ⇒ Boolean

Projects are <task>s with an interior <project> node

Returns:

  • (Boolean)


9
10
11
12
13
14
15
# File 'lib/rubyfocus/items/project.rb', line 9

def self.matches_node?(node)
	return (
		node.name == "task" &&
		(node/"project").size > 0 &&
		(node/"project").first.children.size > 0
	)
end

Instance Method Details

#active?Boolean

Status methods

Returns:

  • (Boolean)


67
# File 'lib/rubyfocus/items/project.rb', line 67

def active?; status == :active; end

#apply_xml(n) ⇒ Object

Apply XML node to project



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubyfocus/items/project.rb', line 40

def apply_xml(n)
	super(n)

	#First, set project
	p = n.at_xpath("xmlns:project")
	# We're not always going to have a project! And this *doesn't* mean that this project is demoted
	if p
		conditional_set(:singleton, 			p.at_xpath("xmlns:singleton"))					{ |e| e.inner_html == "true" }
		conditional_set(:review_interval, p.at_xpath("xmlns:review-interval") ) 	{ |e| Rubyfocus::ReviewPeriod.from_string(e.inner_html) }
		conditional_set(:last_review, 		p.at_xpath("xmlns:last-review"))				{ |e| Time.safely_parse e.inner_html }
		conditional_set(:status,					p.at_xpath("xmlns:status"))							{ |e| e.inner_html.to_sym }							
	end
end

#completed?Boolean

Returns:

  • (Boolean)


69
# File 'lib/rubyfocus/items/project.rb', line 69

def completed?; status == :done; end

#dropped?Boolean

Returns:

  • (Boolean)


70
# File 'lib/rubyfocus/items/project.rb', line 70

def dropped?; status == :dropped; end

#on_hold?Boolean

Returns:

  • (Boolean)


68
# File 'lib/rubyfocus/items/project.rb', line 68

def on_hold?; status == :inactive; end

#to_taskObject


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



74
75
76
77
78
79
80
81
82
# File 'lib/rubyfocus/items/project.rb', line 74

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