Skip to content

Instantly share code, notes, and snippets.

@puneetpandey

puneetpandey/time_sheet.rb Secret

Created Jan 11, 2014
Embed
What would you like to do?
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
You can’t perform that action at this time.