diff options
| author | bricooke | 2010-09-21 12:50:38 -0600 |
|---|---|---|
| committer | bricooke | 2010-09-21 12:50:38 -0600 |
| commit | 5ec73dbf96e51a8ed918527d79df6081ca6f4eb6 (patch) | |
| tree | 389882b73dc75d3c1b5f56b76f29d16475986a1c /lib | |
| parent | 92528d1f63ab83baa5764a0350fa1ad47e0d4bf2 (diff) | |
| download | hcl-5ec73dbf96e51a8ed918527d79df6081ca6f4eb6.tar.bz2 | |
added a resume command to resume the most recently active timer.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hcl/app.rb | 2 | ||||
| -rw-r--r-- | lib/hcl/commands.rb | 10 | ||||
| -rw-r--r-- | lib/hcl/day_entry.rb | 4 |
3 files changed, 16 insertions, 0 deletions
diff --git a/lib/hcl/app.rb b/lib/hcl/app.rb index b208d11..b49c6c5 100644 --- a/lib/hcl/app.rb +++ b/lib/hcl/app.rb @@ -5,6 +5,7 @@ require 'net/http' require 'net/https' ## gem dependencies +require 'rubygems' require 'chronic' require 'trollop' require 'highline/import' @@ -99,6 +100,7 @@ Commands: hcl unset <key> hcl start <task> [msg] hcl stop [msg] + hcl resume hcl note <msg> Examples: diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb index 9e59a90..6d2619b 100644 --- a/lib/hcl/commands.rb +++ b/lib/hcl/commands.rb @@ -87,6 +87,16 @@ module HCl puts "\t#{as_hours total_hours}\ttotal (as of #{current_time})" end + def resume + entry = DayEntry.last + if entry + puts "Resumed #{entry} (at #{current_time})" + entry.toggle + else + puts "No timers found" + end + end + private def current_time Time.now.strftime('%I:%M %p').downcase diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb index b77d597..d4fe69d 100644 --- a/lib/hcl/day_entry.rb +++ b/lib/hcl/day_entry.rb @@ -42,6 +42,10 @@ module HCl def self.with_timer all.detect {|t| t.running? } end + + def self.last + all.sort {|a,b| a.updated_at<=>b.updated_at}[-1] + end def running? !@data[:timer_started_at].nil? && !@data[:timer_started_at].empty? |
