Skip to content

Instantly share code, notes, and snippets.

@FaisalFehad
Created December 14, 2016 22:30
Show Gist options
  • Save FaisalFehad/f5ffe53450c4190c3e27240a70010c99 to your computer and use it in GitHub Desktop.
Save FaisalFehad/f5ffe53450c4190c3e27240a70010c99 to your computer and use it in GitHub Desktop.
Simple script to sum the weekly worked time
#!/usr/bin/ruby
class TimeSheet
attr_accessor(:start_time, :finish_time, :launch, :breaks, :meeting)
def input
week = ['Monday', 'Tuesday','Wednesday', 'Thursday','Friday','Saturday','Sunday' ]
week.each do |d|
puts "What time did you start? on " + d
@start_time = gets
puts "What time did you finish working? on " + d
@finish_time = gets
puts "Total launch you had on " + d
@launch = gets
puts "total Breaks you had? on " + d
@breaks = gets
puts "=" * 40
puts "Timesheet of #{d}:"
to_s
end
end
def total
total = @finish_time.to_f - @launch.to_f - @start_time.to_f
@week_total =+ total.to_f
end
def week_total
@week_total = 0
puts "Total of the week: #{@week_total} hours"
end
# Prints the results as string
def to_s
puts " "
puts "Total woked hours #{total} hours"
puts "-" * 40
puts "Started at: #{start_time}"
puts "Finished at: #{finish_time}"
puts "Total breaks of: #{breaks}"
puts "Total launch time of: #{launch}"
puts "=" * 40
end
end
day = TimeSheet.new
day.input
day.week_total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment