Class: Things::Focus
- Inherits:
-
Object
- Object
- Things::Focus
- Defined in:
- lib/things/focus.rb
Constant Summary collapse
- FOCUS_TYPES =
%w[FocusInbox FocusLogbook FocusMaybe FocusNextActions FocusTickler FocusToday FocusTrash].freeze
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(name, doc) ⇒ Focus
constructor
A new instance of Focus.
- #tasks(options = {}) ⇒ Object (also: #todos)
- #type_id ⇒ Object
- #type_name ⇒ Object
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
#id ⇒ Object
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( = {}) ||= {} # 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!() @tasks.sort_by &:position end |
#type_id ⇒ Object
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_name ⇒ Object
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 |