Skip to content

Instantly share code, notes, and snippets.

@puneetpandey
Created January 11, 2014 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save puneetpandey/2274eca4ea7a3dad0745 to your computer and use it in GitHub Desktop.
Save puneetpandey/2274eca4ea7a3dad0745 to your computer and use it in GitHub Desktop.
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