forked from alexch/learn_ruby
-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathtimer.rb
More file actions
32 lines (30 loc) · 761 Bytes
/
timer.rb
File metadata and controls
32 lines (30 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Timer
#write your code here
attr_accessor :hours, :minutes, :seconds, :time_string
def initialize
@seconds = 0
@hours = 0
@minutes = 0
@time_string = "00:00:00"
end
def seconds=(seconds)
@seconds = seconds
if(seconds > 3599)
@hours = seconds / 3600
@minutes = (seconds - (@hours * 3600)) / 60
@seconds = seconds - (@hours * 3600) - (@minutes * 60)
elsif(seconds > 59)
@seconds = seconds % 60
@minutes = seconds / 60
@hours = 0
else
@seconds = seconds
@hours = 0
@minutes = 0
end
second_string = "%0.2d" % [@seconds]
minute_string = "%0.2d" % [@minutes]
hour_string = "%0.2d" % [@hours]
@time_string = hour_string + ":" + minute_string + ":" + second_string
end
end