diff options
| author | Zack Hobson | 2009-07-21 10:53:43 -0700 |
|---|---|---|
| committer | Zack Hobson | 2009-07-21 10:53:43 -0700 |
| commit | 30239dc8f61b86335eb8a4de9bdbbe38b425aa0b (patch) | |
| tree | 45688ede37e2a57bb7685d4bebb7e978b9e73bbe /lib | |
| parent | 538986dd21356b248806fc979998caa64cdedb50 (diff) | |
| download | hcl-30239dc8f61b86335eb8a4de9bdbbe38b425aa0b.tar.bz2 | |
Added stop command, closes #5.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hcl.rb | 14 | ||||
| -rw-r--r-- | lib/hcl/day_entry.rb | 15 | ||||
| -rw-r--r-- | lib/hcl/task.rb | 1 |
3 files changed, 27 insertions, 3 deletions
@@ -122,12 +122,23 @@ EOM puts "Started timer for #{task}" end + def stop + entry = DayEntry.with_timer + if entry + entry.toggle + puts "Stopped #{entry}" + else + puts "No running timers found." + end + end + def show *args date = args.empty? ? nil : Chronic.parse(args.join(' ')) total_hours = 0.0 DayEntry.all(date).each do |day| # TODO more information and formatting options - puts "\t#{as_hours day.hours}\t#{day.project} #{day.notes}"[0..78] + running = day.running? ? '(running) ' : '' + puts "\t#{as_hours day.hours}\t#{running}#{day.project} #{day.notes}"[0..78] total_hours = total_hours + day.hours.to_f end puts "\t" + '-' * 13 @@ -145,7 +156,6 @@ EOM end # TODO implement the following commands - alias stop not_implemented alias add not_implemented alias rm not_implemented diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb index e23f7e9..42f52f4 100644 --- a/lib/hcl/day_entry.rb +++ b/lib/hcl/day_entry.rb @@ -15,14 +15,27 @@ class HCl def self.from_xml xml doc = REXML::Document.new xml Task.cache_tasks doc - doc.root.elements.collect('day_entries/day_entry') do |day| + doc.root.elements.collect('*/day_entry') do |day| new xml_to_hash(day) end 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 diff --git a/lib/hcl/task.rb b/lib/hcl/task.rb index 1a742ce..5923867 100644 --- a/lib/hcl/task.rb +++ b/lib/hcl/task.rb @@ -38,6 +38,7 @@ class HCl EOT days.first end + end end |
