Published in: Ruby
#!/usr/bin/env ruby text = STDIN.read lines = text.split("\n") totalHr = 0 totalMin = 0 i = 1 for line in lines do begHr = line[0,2].to_i begMin = line[3,2].to_i endHr = line[8,2].to_i endMin = line[11,2].to_i hourage = line[0,13] desc = line[14, (line.length - 14)] if line != "" if desc == nil desc = " " end if endHr < begHr endHr = endHr + 24 end hoursSpent = endHr - begHr if endMin < begMin endMin = endMin + 60 hoursSpent = hoursSpent - 1 end minSpent = endMin - begMin puts hourage + " (" + hoursSpent.to_s.rjust(2,'0') + "." + minSpent.to_s.rjust(2,'0') + ") " + desc totalHr = totalHr + hoursSpent totalMin = totalMin + minSpent i += 1 end end while totalMin >= 60 totalMin = totalMin - 60 totalHr = totalHr + 1 end puts "\n" + " TOTAL: " + totalHr.to_s.rjust(2,'0') + "." + totalMin.to_s.rjust(2,'0')
You need to login to post a comment.
