Skip to content

Instantly share code, notes, and snippets.

@renaehodgkins
Created November 28, 2008 02:29
Show Gist options
  • Save renaehodgkins/29883 to your computer and use it in GitHub Desktop.
Save renaehodgkins/29883 to your computer and use it in GitHub Desktop.
require 'yaml'
def time_get
puts "Please hit Enter to start time tracking"
if gets.chomp == ""
Time.now
else
time_get
end
end
def time_stop
puts "Please hit Enter again to stop time tracking"
if gets.chomp == ""
Time.now
else
time_stop
end
end
def time_track
start_time = time_get
puts "Time tracking started at #{start_time}"
end_time = time_stop
puts "Time tracking ended at #{end_time}"
end_time - start_time
end
def time_format(time)
Time.at(time).gmtime.strftime('%H:%M:%S')
end
#gets all of the times stored in the times.yml file then totals them in total_times.yml
def add_times
totaled_times = YAML.load(open('times.yml'))
total = totaled_times.inject(0) {|sum, time| sum = sum + time}
open('totaled_times.yml', 'w') {|f| f << time_format(total)}
end
#Storing all of the time entries in a yml file and reading them into an array
all_times = YAML.load(open('times.yml'))
all_times = [] unless all_times
all_times << time_track
open('times.yml', 'w') {|f| f << all_times.to_yaml}
add_times
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment