Class: HCl::DayEntry
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utility
#as_hours, #current_time, #fail, #get_ident, #get_starting_time, #get_task, #get_task_ids, #time2float
configure, connect, delete, get, http_do, #id, #method_missing, post, #respond_to?, xml_to_hash
Constructor Details
#initialize(*args) ⇒ DayEntry
Returns a new instance of DayEntry.
70
71
72
73
|
# File 'lib/hcl/day_entry.rb', line 70
def initialize *args
super
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class HCl::TimesheetResource
Class Method Details
.all(date = nil) ⇒ Object
Get the time sheet entries for a given day. If no date is provided defaults to today.
9
10
11
12
|
# File 'lib/hcl/day_entry.rb', line 9
def self.all date = nil
url = date.nil? ? 'daily' : "daily/#{date.strftime '%j/%Y'}"
from_xml get(url)
end
|
.from_xml(xml) ⇒ Object
22
23
24
25
26
27
28
29
|
# File 'lib/hcl/day_entry.rb', line 22
def self.from_xml xml
doc = REXML::Document.new xml
raise Failure, "No root node in XML document: #{xml}" if doc.root.nil?
Task.cache_tasks doc
doc.root.elements.collect('//day_entry') do |day|
new xml_to_hash(day)
end
end
|
.last ⇒ Object
62
63
64
|
# File 'lib/hcl/day_entry.rb', line 62
def self.last
all.sort {|a,b| a.updated_at<=>b.updated_at}[-1]
end
|
.last_by_task(project_id, task_id) ⇒ Object
57
58
59
60
|
# File 'lib/hcl/day_entry.rb', line 57
def self.last_by_task project_id, task_id
all.sort {|a,b| b.updated_at<=>a.updated_at}.
detect {|t| t.project_id == project_id && t.task_id == task_id }
end
|
.with_timer(date = nil) ⇒ Object
53
54
55
|
# File 'lib/hcl/day_entry.rb', line 53
def self.with_timer date=nil
all(date).detect {|t| t.running? }
end
|
Instance Method Details
#append_note(new_notes) ⇒ Object
Append a string to the notes for this task.
45
46
47
48
49
50
51
|
# File 'lib/hcl/day_entry.rb', line 45
def append_note new_notes
(self.notes << "\n#{new_notes}").lstrip!
DayEntry.post "daily/update/#{id}",
%{<request><notes>#{notes}</notes><hours>#{hours}</hours></request>}
end
|
Returns the hours formatted as “HH:MM”
81
82
83
|
# File 'lib/hcl/day_entry.rb', line 81
def formatted_hours
as_hours hours
end
|
#notes ⇒ Object
40
41
42
|
# File 'lib/hcl/day_entry.rb', line 40
def notes
super || @data[:notes] = ''
end
|
#running? ⇒ Boolean
66
67
68
|
# File 'lib/hcl/day_entry.rb', line 66
def running?
!@data[:timer_started_at].nil? && !@data[:timer_started_at].empty?
end
|
#task ⇒ Object
18
19
20
|
# File 'lib/hcl/day_entry.rb', line 18
def task
@data[:task]
end
|
#to_s ⇒ Object
14
15
16
|
# File 'lib/hcl/day_entry.rb', line 14
def to_s
"#{client} - #{project} - #{task} (#{formatted_hours})"
end
|
#toggle ⇒ Object
75
76
77
78
|
# File 'lib/hcl/day_entry.rb', line 75
def toggle
DayEntry.get("daily/timer/#{id}")
self
end
|