Sha256: b16273d5dc1e3867bac5a7a50268c50bfd60dd147a55d9b230e9813d64a4929c

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

class HCl 
  class DayEntry < TimesheetResource
    # Get the time sheet entries for a given day. If no date is provided
    # defaults to today.
    def self.all date = nil
      url = date.nil? ? 'daily' : "daily/#{date.strftime '%j/%Y'}"
      from_xml get(url)
    end

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

    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

    # Append a string to the notes for this task.
    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

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

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

    def initialize *args
      super
      # TODO cache client/project names and ids
    end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
zenhob-hcl-0.1.1 lib/hcl/day_entry.rb
zenhob-hcl-0.1.2 lib/hcl/day_entry.rb
zenhob-hcl-0.1.3 lib/hcl/day_entry.rb