Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment