lib/hcl.rb in zenhob-hcl-0.1.3 vs lib/hcl.rb in zenhob-hcl-0.2.0

- old
+ new

@@ -5,10 +5,11 @@ require 'chronic' require 'trollop' require 'highline/import' +require 'hcl/utility' require 'hcl/timesheet_resource' require 'hcl/project' require 'hcl/task' require 'hcl/day_entry' @@ -23,10 +24,12 @@ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE end end class HCl + include Utility + VERSION_FILE = File.dirname(__FILE__) + '/../VERSION.yml' SETTINGS_FILE = "#{ENV['HOME']}/.hcl_settings" CONFIG_FILE = "#{ENV['HOME']}/.hcl_config" class UnknownCommand < StandardError; end @@ -170,10 +173,15 @@ def aliases @settings.keys.select { |s| s =~ /^task\./ }.map { |s| s.slice(5..-1) } end def start *args + starting_time = args.detect {|x| x =~ /^\+\d*(\.|:)\d+$/ } + if starting_time + args.delete(starting_time) + starting_time = time2float starting_time + end ident = args.shift task_ids = if @settings.key? "task.#{ident}" @settings["task.#{ident}"].split(/\s+/) else [ident, args.shift] @@ -181,12 +189,12 @@ task = Task.find *task_ids if task.nil? puts "Unknown project/task alias, try one of the following: #{aliases.join(', ')}." exit 1 end - task.start(*args) - puts "Started timer for #{task}." + timer = task.start(:starting_time => starting_time, :note => args.join(' ')) + puts "Started timer for #{timer}." end def stop entry = DayEntry.with_timer if entry @@ -210,22 +218,15 @@ 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 running = day.running? ? '(running) ' : '' - puts "\t#{as_hours day.hours}\t#{running}#{day.project} #{day.notes}"[0..78] + puts "\t#{day.formatted_hours}\t#{running}#{day.project} #{day.notes}"[0..78] total_hours = total_hours + day.hours.to_f end puts "\t" + '-' * 13 puts "\t#{as_hours total_hours}\ttotal" - end - - # Convert from decimal to a string of the form HH:MM. - def as_hours hours - minutes = hours.to_f * 60.0 - sprintf "%d:%02d", (minutes / 60).to_i, (minutes % 60).to_i end end