module WorkingTimes::State

Private Instance Methods

current_work() click to toggle source

return what kind of working on

# File lib/working_times/state.rb, line 12
def current_work
  File.readlines(path_working_flag).last.chomp
end
finish_work() click to toggle source
# File lib/working_times/state.rb, line 21
def finish_work
  puts "You were working about #{worked_time}."
  File.delete(path_working_flag)
  puts FINISH_MSG.sample
end
start_work() click to toggle source
# File lib/working_times/state.rb, line 16
def start_work
  File.write(path_working_flag, current_term)
  puts START_MSG.sample
end
worked_time() click to toggle source
# File lib/working_times/state.rb, line 27
def worked_time
  last_record = CSV.read(path_current_term).last
  started_at  = Time.parse(last_record[0])
  finished_at = Time.parse(last_record[1])
  duration    = (finished_at - started_at).to_i
  hour = duration / 3600
  min  = (duration - 3600 * hour) / 60
  "#{hour.to_s.rjust(2, '0')} hour #{min.to_s.rjust(2, '0')} min"
end
working?() click to toggle source
# File lib/working_times/state.rb, line 7
def working?
  File.exist?(path_working_flag)
end