summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbricooke2010-09-21 12:50:38 -0600
committerbricooke2010-09-21 12:50:38 -0600
commit5ec73dbf96e51a8ed918527d79df6081ca6f4eb6 (patch)
tree389882b73dc75d3c1b5f56b76f29d16475986a1c
parent92528d1f63ab83baa5764a0350fa1ad47e0d4bf2 (diff)
downloadhcl-5ec73dbf96e51a8ed918527d79df6081ca6f4eb6.tar.bz2
added a resume command to resume the most recently active timer.
-rw-r--r--.gitignore2
-rw-r--r--lib/hcl/app.rb2
-rw-r--r--lib/hcl/commands.rb10
-rw-r--r--lib/hcl/day_entry.rb4
4 files changed, 18 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 3d3e64f..18004df 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,5 @@ pkg
tags
doc
.yardoc
+.rvmrc
+.rvmrc.*
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?