Skip to content

Commit

Permalink
added a resume command to resume the most recently active timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
bricooke committed Sep 21, 2010
1 parent 92528d1 commit 5ec73db
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ pkg
tags
doc
.yardoc
.rvmrc
.rvmrc.*
2 changes: 2 additions & 0 deletions lib/hcl/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'net/https'

## gem dependencies
require 'rubygems'
require 'chronic'
require 'trollop'
require 'highline/import'
Expand Down Expand Up @@ -99,6 +100,7 @@ def process_args *args
hcl unset <key>
hcl start <task> [msg]
hcl stop [msg]
hcl resume
hcl note <msg>
Examples:
Expand Down
10 changes: 10 additions & 0 deletions lib/hcl/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ def show *args
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
Expand Down
4 changes: 4 additions & 0 deletions lib/hcl/day_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def append_note new_notes
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?
Expand Down

0 comments on commit 5ec73db

Please sign in to comment.