summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/hcl.rb14
-rw-r--r--lib/hcl/day_entry.rb15
-rw-r--r--lib/hcl/task.rb1
3 files changed, 27 insertions, 3 deletions
diff --git a/lib/hcl.rb b/lib/hcl.rb
index 894c5ee..883ded6 100644
--- a/lib/hcl.rb
+++ b/lib/hcl.rb
@@ -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