Class: HCl::DayEntry

Inherits:
TimesheetResource show all
Includes:
Utility
Defined in:
lib/hcl/day_entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utility

#as_hours, #time2float

Methods inherited from TimesheetResource

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

Constructor Details

#initialize(*args) ⇒ DayEntry

Returns a new instance of DayEntry.



44
45
46
47
# File 'lib/hcl/day_entry.rb', line 44

def initialize *args
  super
  # TODO cache client/project names and ids
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.



7
8
9
10
# File 'lib/hcl/day_entry.rb', line 7

def self.all date = nil
  url = date.nil? ? 'daily' : "daily/#{date.strftime '%j/%Y'}"
  from_xml get(url)
end

.from_xml(xml) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/hcl/day_entry.rb', line 16

def self.from_xml xml
  doc = REXML::Document.new xml
  Task.cache_tasks doc
  doc.root.elements.collect('//day_entry') do |day|
    new xml_to_hash(day)
  end
end

.with_timerObject



36
37
38
# File 'lib/hcl/day_entry.rb', line 36

def self.with_timer
  all.detect {|t| t.running? }
end

Instance Method Details

#append_note(new_notes) ⇒ Object

Append a string to the notes for this task.



25
26
27
28
29
30
31
32
33
34
# File 'lib/hcl/day_entry.rb', line 25

def append_note new_notes
  # If I don't include hours it gets reset.
  # This doens't appear to be the case for task and project.
  DayEntry.post("daily/update/#{id}", <<-EOD)
  <request>
    <notes>#{notes << " #{new_notes}"}</notes>
    <hours>#{hours}</hours>
  </request>
  EOD
end

#formatted_hoursObject

Returns the hours formatted as “HH:MM”



55
56
57
# File 'lib/hcl/day_entry.rb', line 55

def formatted_hours
  as_hours hours
end

#running?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/hcl/day_entry.rb', line 40

def running?
  !@data[:timer_started_at].nil? && !@data[:timer_started_at].empty?
end

#to_sObject



12
13
14
# File 'lib/hcl/day_entry.rb', line 12

def to_s
  "#{client} #{project} #{task} (#{formatted_hours})"
end

#toggleObject



49
50
51
52
# File 'lib/hcl/day_entry.rb', line 49

def toggle
  DayEntry.get("daily/timer/#{id}")
  self
end