lib/txt_timesheet.rb in txt_timesheet-1.1.11 vs lib/txt_timesheet.rb in txt_timesheet-1.1.12

- old
+ new

@@ -1,26 +1,18 @@ # frozen_string_literal: true + require 'time' # Treat past files as a parameter and calculate total hours worked class TxtTimesheet - def initialize @can_parse = false end def can_parse? @can_parse end - def convert(time_in_minutes) - ### Convert working time to hh:mm format - hours = time_in_minutes / 60 - minutes = time_in_minutes - hours * 60 - ## Add 0 to keep hh: mm format - "%02d:%02d" % [hours, minutes] - end - def set_can_parse(line) if @can_parse @can_parse = false if line.start_with? '## ' else @can_parse = true if line.start_with? '## Timesheet' @@ -49,25 +41,25 @@ end while index < time.count sum_time = time_in_sec[index + 1] - time_in_sec[index] + sum_time - index +=2 + index += 2 end ### total_sec = sum_time # phrase = 'xixixococo' { file_name: filename, - file_time: total_sec, + file_time: total_sec # phrase: phrase } end - def process_results(results=[]) + def process_results(results = []) output = [] total = [] total_time = 0 output << 'REPORT:' @@ -75,17 +67,17 @@ file_name = result[:file_name] time_file = result[:file_time] total_time += time_file # phrase = result[:phrase] time_file = Time.at(time_file).utc - output << "#{file_name}: #{time_file.strftime("%H:%M")} hours \n" + output << "#{file_name}: #{time_file.strftime('%H:%M')} hours \n" # total_time = result[:file_time] end total = total_time.divmod(3600) total[1] /= 60 total[1] = total.last.to_i - output << "Total Hours: #{total.join(":")} hours\n" + output << format("Total Hours: %02d:%02d hours\n", total[0],total[1]) output end def run