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, #current_time, #fail, #get_ident, #get_starting_time, #get_task, #get_task_ids, #time2float

Methods inherited from TimesheetResource

_prepare_resource, collection_name, #id, #initialize, #method_missing, resource, resources, #respond_to?, underscore_name

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

.last(http) ⇒ Object



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

def self.last http
  today(http).sort {|a,b| a.updated_at<=>b.updated_at}[-1]
end

.last_by_task(http, project_id, task_id) ⇒ Object



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

def self.last_by_task http, project_id, task_id
  today(http).sort {|a,b| b.updated_at<=>a.updated_at}.
    detect {|t| t.project_id == project_id && t.task_id == task_id }
end

.with_timer(http, date = nil) ⇒ Object



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

def self.with_timer http, date=nil
  daily(http, date).detect {|t| t.running? }
end

Instance Method Details

#append_note(http, new_notes) ⇒ Object

Append a string to the notes for this task.



32
33
34
35
36
37
# File 'lib/hcl/day_entry.rb', line 32

def append_note http, new_notes
  # If I don't include hours it gets reset.
  # This doens't appear to be the case for task and project.
  (self.notes << "\n#{new_notes}").lstrip!
  http.post "daily/update/#{id}", notes:notes, hours:hours
end

#cancel(http) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/hcl/day_entry.rb', line 18

def cancel http
  begin
    http.delete("daily/delete/#{id}")
  rescue HarvestMiddleware::Failure
    return false
  end
  true
end

#formatted_hoursObject

Returns the hours formatted as “HH:MM”



62
63
64
# File 'lib/hcl/day_entry.rb', line 62

def formatted_hours
  as_hours hours
end

#notesObject



27
28
29
# File 'lib/hcl/day_entry.rb', line 27

def notes
  super || @data[:notes] = ''
end

#running?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/hcl/day_entry.rb', line 52

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

#taskObject



14
15
16
# File 'lib/hcl/day_entry.rb', line 14

def task
  @data[:task]
end

#to_sObject



10
11
12
# File 'lib/hcl/day_entry.rb', line 10

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

#toggle(http) ⇒ Object



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

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