Class: HCl::DayEntry
- Inherits:
-
TimesheetResource
- Object
- TimesheetResource
- HCl::DayEntry
- Includes:
- Utility
- Defined in:
- lib/hcl/day_entry.rb
Class Method Summary collapse
-
.all(date = nil) ⇒ Object
Get the time sheet entries for a given day.
- .from_xml(xml) ⇒ Object
- .with_timer ⇒ Object
Instance Method Summary collapse
-
#append_note(new_notes) ⇒ Object
Append a string to the notes for this task.
-
#formatted_hours ⇒ Object
Returns the hours formatted as “HH:MM”.
-
#initialize(*args) ⇒ DayEntry
constructor
A new instance of DayEntry.
- #notes ⇒ Object
- #running? ⇒ Boolean
- #to_s ⇒ Object
- #toggle ⇒ Object
Methods included from Utility
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.
50 51 52 53 |
# File 'lib/hcl/day_entry.rb', line 50 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.
8 9 10 11 |
# File 'lib/hcl/day_entry.rb', line 8 def self.all date = nil url = date.nil? ? 'daily' : "daily/#{date.strftime '%j/%Y'}" from_xml get(url) end |
.from_xml(xml) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/hcl/day_entry.rb', line 17 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 |
.with_timer ⇒ Object
42 43 44 |
# File 'lib/hcl/day_entry.rb', line 42 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.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hcl/day_entry.rb', line 31 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_hours ⇒ Object
Returns the hours formatted as “HH:MM”
61 62 63 |
# File 'lib/hcl/day_entry.rb', line 61 def formatted_hours as_hours hours end |
#notes ⇒ Object
26 27 28 |
# File 'lib/hcl/day_entry.rb', line 26 def notes super || @data[:notes] = '' end |
#running? ⇒ Boolean
46 47 48 |
# File 'lib/hcl/day_entry.rb', line 46 def running? !@data[:timer_started_at].nil? && !@data[:timer_started_at].empty? end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/hcl/day_entry.rb', line 13 def to_s "#{client} #{project} #{task} (#{formatted_hours})" end |