This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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