diff options
| -rw-r--r-- | README.markdown | 15 | ||||
| -rw-r--r-- | lib/hcl.rb | 26 | ||||
| -rw-r--r-- | lib/hcl/day_entry.rb | 10 | 
3 files changed, 33 insertions, 18 deletions
| diff --git a/README.markdown b/README.markdown index 0b02669..b44b416 100644 --- a/README.markdown +++ b/README.markdown @@ -17,22 +17,23 @@ feature is a simple view of today's timesheet. To try it out:   * Ruby (tested with 1.8.7)   * RubyGems   * Curb curl library (gem install curb) + * Chronic date-parsing library (gem install chronic)  ## Usage -NOTE only the first command is implemented, and arguments are ignored. +NOTE only the show command is implemented -    hcl [opts] show [date] -    hcl [opts] add <project> <task> <duration> [msg] -    hcl [opts] rm [entry_id] -    hcl [opts] start <project> <task> [msg] -    hcl [opts] stop [msg] +    hcl show [date] +    hcl add <project> <task> <duration> [msg] +    hcl rm [entry_id] +    hcl start <project> <task> [msg] +    hcl stop [msg]  ## TODO   * Implement time-tracking API methods:     - display today's time sheet (done) -   - display any time sheet by date +   - display any time sheet by date (done)     - get time sheet entry     - toggle a timer     - post a time sheet entry @@ -2,6 +2,7 @@ require 'yaml'  require 'rubygems'  require 'curb' +require 'chronic'  require 'hcl/day_entry' @@ -17,7 +18,7 @@ class HCl      hcl = new(@@conf_file).process_args *args      if command        if hcl.respond_to? command -        hcl.send command +        hcl.send command, *args        else          raise UnknownCommand, "unrecognized command `#{command}'"        end @@ -36,11 +37,17 @@ class HCl      puts <<-EOM      Usage: -    hcl [opts] add <project> <task> <duration> [msg] -    hcl [opts] rm [entry_id] -    hcl [opts] start <project> <task> [msg] -    hcl [opts] stop [msg] -    hcl [opts] show [date] +    hcl show [date] +    hcl add <project> <task> <duration> [msg] +    hcl rm [entry_id] +    hcl start <project> <task> [msg] +    hcl stop [msg] + +    Examples: + +    hcl show 2009-07-15 +    hcl show yesterday +    hcl show last tuesday      EOM    end    def help; self.class.help; end @@ -50,11 +57,12 @@ class HCl      self    end -  def show +  def show *args +    date = args.empty? ? nil : Chronic.parse(args.join(' '))      total_hours = 0.0 -    DayEntry.all.each do |day| +    DayEntry.all(date).each do |day|        # TODO more information and formatting options -      puts "\t#{day.hours}\t#{day.project} (#{day.notes})"[0..78] +      puts "\t#{day.hours}\t#{day.project} #{day.notes}"[0..78]        total_hours = total_hours + day.hours.to_f      end      puts "\t" + '-' * 13 diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb index c4e24f4..41570b4 100644 --- a/lib/hcl/day_entry.rb +++ b/lib/hcl/day_entry.rb @@ -51,8 +51,9 @@ class HCl    end    class DayEntry < TimesheetResource -    def self.all -      doc = REXML::Document.new perform('daily') +    def self.all date = nil +      url = date.nil? ? 'daily' : "daily/#{date.strftime '%j/%Y'}" +      doc = REXML::Document.new perform url        doc.root.elements.collect('day_entries/day_entry') do |day|          new(            day.elements.map { |e| e.name }.inject({}) do |a, f| @@ -62,5 +63,10 @@ class HCl          )        end      end + +    def initialize *args +      super +      # TODO cache client/project names and ids +    end    end  end | 
