Class: HCl::Task

Inherits:
TimesheetResource show all
Defined in:
lib/hcl/task.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TimesheetResource

configure, get, https_do, #id, #initialize, #method_missing, post, xml_to_hash

Constructor Details

This class inherits a constructor from HCl::TimesheetResource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HCl::TimesheetResource

Class Method Details

.allObject



18
19
20
# File 'lib/hcl/task.rb', line 18

def self.all
  YAML.load File.read(File.join(ENV['HOME'],'.hcl_tasks'))
end

.cache_tasks(doc) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/hcl/task.rb', line 3

def self.cache_tasks doc
  tasks = []
  doc.root.elements.collect('projects/project') do |project_elem|
    project = Project.new xml_to_hash(project_elem)
    tasks.concat(project_elem.elements.collect('tasks/task') do |task|
      new xml_to_hash(task).merge(:project => project)
    end)
  end
  unless tasks.empty?
    File.open(File.join(ENV['HOME'],'.hcl_tasks'), 'w') do |f|
      f.write tasks.uniq.to_yaml
    end
  end
end

.find(project_id, id) ⇒ Object



22
23
24
25
26
# File 'lib/hcl/task.rb', line 22

def self.find project_id, id
  all.detect do |t|
    t.project.id.to_i == project_id.to_i && t.id.to_i == id.to_i
  end
end

Instance Method Details

#add(opts) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hcl/task.rb', line 32

def add opts
  notes = opts[:note]
  starting_time = opts[:starting_time] || 0
  days = DayEntry.from_xml Task.post("daily/add", <<-EOT)
  <request>
    <notes>#{notes}</notes>
    <hours>#{starting_time}</hours>
    <project_id type="integer">#{project.id}</project_id>
    <task_id type="integer">#{id}</task_id>
    <spent_at type="date">#{Date.today}</spent_at>
  </request>
  EOT
  days.first
end

#start(opts) ⇒ Object



47
48
49
50
# File 'lib/hcl/task.rb', line 47

def start opts
  day = add opts
  DayEntry.from_xml(Task.get("daily/timer/#{day.id}")).first
end

#to_sObject



28
29
30
# File 'lib/hcl/task.rb', line 28

def to_s
  "#{project.name} #{name}"
end