Module: Projects

Included in:
Things
Defined in:
lib/harvestthings/things/projects.rb

Instance Method Summary collapse

Instance Method Details

#project(id) ⇒ Hpricot

project - grab the Hpricot element of the project using the id

Parameters:

  • - (id)

    the string of the project’s id

Returns:

  • (Hpricot)
    • an Hpricot XML object



30
31
32
# File 'lib/harvestthings/things/projects.rb', line 30

def project(id)
  @xml.search("object[@id='#{id}']")
end

#project_area(id) ⇒ String

project_area - grab the area of the project using the id

Parameters:

  • - (id)

    the string of the project’s attribute id

Returns:

  • (String)
    • a cleaned and formatted area string



48
49
50
51
52
53
# File 'lib/harvestthings/things/projects.rb', line 48

def project_area(id)
  project = @xml.search("object[@id='#{id}']")
  area = project.search("relationship[@name='parent']")
  area_id = area.attr('idrefs').to_s
  area_id == "" ? "default" : project_title(area_id)
end

#project_title(id) ⇒ String

project_title - grab the title of the project using the id

Parameters:

  • - (id)

    the string of the project’s attribute id

Returns:

  • (String)
    • a cleaned and formatted title string



38
39
40
41
42
# File 'lib/harvestthings/things/projects.rb', line 38

def project_title(id)
  project = @xml.search("object[@id='#{id}']")
  title = project.search("attribute[@name='title']")
  clean(title.innerHTML.to_s)
end

#projectsHpricot

projects - grab an array of the various project ids from the xml

Parameters:

  • - (id)

    the string of the project’s id

Returns:

  • (Hpricot)
    • an Hpricot XML object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/harvestthings/things/projects.rb', line 6

def projects
  # find all projects from the first OBJECT node
  first_obj = @xml.at('object')
  
  if first_obj.search("relationship[@destination='TODO']").length != 0 
    first_obj.search("relationship[@destination='TODO']") do |elem| # older versions of Things
        return elem.attributes["idrefs"].to_s.split(" ")
      end
    else
      @xml.search("attribute[@name='title']") do |elem| # newer versions of Things
        if elem.html == "Projects"
          elem.parent.search("relationship[@name='focustodos']") do |e|
            return e.attributes["idrefs"].to_s.split(" ")
          end
        end
      end
  end
  
end