aboutsummaryrefslogtreecommitdiff
path: root/stop.rb
diff options
context:
space:
mode:
Diffstat (limited to 'stop.rb')
-rw-r--r--stop.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/stop.rb b/stop.rb
new file mode 100644
index 0000000..fff5744
--- /dev/null
+++ b/stop.rb
@@ -0,0 +1,32 @@
+"""
+This file is part of cassiopeia and licensed
+under the GNU Public License 3.0 (or later)
+
+cassiopeia-stop - stop working on an account
+
+This file is included and run from cass(1)
+"""
+
+require "time"
+require_relative "time_util"
+
+def stop(account, round, file = [])
+ rel = file.select { |i| i[:title].to_s.include? account }
+
+ # This is a kind of fuzzy find
+ account = rel[0][:title].to_s[0..-2]
+
+ jobs = rel.select { |i| i[:stop] == nil }
+ if jobs.length == 0
+ STDERR.puts "No unfinished accounts for '#{account}'!"
+ exit 2
+ end
+
+ STDERR.puts "[Warn]: More than one dangling account!" unless jobs.length == 1
+ job = jobs[0]
+ line, _ = job[:title].line_and_column
+
+ # We return the line number too, so that we can inset correctly
+ return line, "#{account}:\
+ #{job[:start]} - #{round ? Time.now.round : Time.now}"
+end