Class: Things::Focus

Inherits:
Object
  • Object
show all
Defined in:
lib/things/focus.rb

Constant Summary collapse

FOCUS_TYPES =
%w[FocusInbox FocusLogbook FocusMaybe FocusNextActions FocusTickler FocusToday FocusTrash].freeze

Instance Method Summary collapse

Constructor Details

#initialize(name, doc) ⇒ Focus

Returns a new instance of Focus.



5
6
7
8
9
# File 'lib/things/focus.rb', line 5

def initialize(name, doc)
  @name     = name
  @doc      = doc
  @xml_node = @doc.at("//object[@type='FOCUS']/attribute[@name='identifier'][text()='#{type_name}']/..")
end

Instance Method Details

#idObject



22
23
24
# File 'lib/things/focus.rb', line 22

def id
  @id ||= @xml_node.attributes['id']
end

#tasks(options = {}) ⇒ Object Also known as: todos



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/things/focus.rb', line 30

def tasks(options = {})
  options ||= {} # when options == nil
  
  selector = "//object[@type='TODO']/attribute[@name='focustype'][text()='#{type_id}']/.."
  @all_tasks ||= @doc.search(selector).map do |task_xml|
    Task.new(task_xml, @doc)
  end

  filter_tasks!(options)
  
  @tasks.sort_by &:position
end

#type_idObject



26
27
28
# File 'lib/things/focus.rb', line 26

def type_id
  @type_id ||= @xml_node.at("/attribute[@name='focustype']").inner_text
end

#type_nameObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/things/focus.rb', line 11

def type_name
  name = case @name.to_s
    when /next/i            then "FocusNextActions"
    when "someday", "later" then "FocusMaybe"
    when "scheduled"        then "FocusTickler"
    else "Focus" + @name.to_s.capitalize
  end
  raise Things::InvalidFocus, name unless FOCUS_TYPES.member?(name)
  name
end