require 'spreadsheet' | |
Spreadsheet.client_encoding = 'UTF-8' | |
class TimeSheet | |
def calculate_total_working_hours | |
employeeHash = {} | |
book = Spreadsheet.open 'timesheet.xls' | |
default_sheet = book.worksheet 0 # If there are multiple worksheet it will take the 1rst. | |
default_sheet.each 1 do |row| # This will start from the 1st record. | |
employeeHash[row[0]] = employeeHash.has_key?(row[0]) ? employeeHash[row[0]] + row[1] : row[1] | |
end | |
puts "Timesheet entry***** #{employeeHash.inspect}" | |
end | |
end | |
time_sheet = TimeSheet.new | |
time_sheet.calculate_total_working_hours |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment