Class: DayTimeSeconds
Overview
Helper class for time of day storage in database as integer value
Instance Attribute Summary
Attributes included from DayTimeBase
#number
Class Method Summary
collapse
Instance Method Summary
collapse
#coerce, #compare_operation, #initialize, #inspect, #quoted_id
Class Method Details
.string_to_number(string) ⇒ Object
25
26
27
28
29
|
# File 'app/services/day_time_seconds.rb', line 25
def string_to_number(string)
return nil unless string.present?
hours, minutes, seconds = string.split(':')
hours.to_i * 3600 + minutes.to_i * 60 + seconds.to_i
end
|
Instance Method Details
#hours ⇒ Object
20
21
22
|
# File 'app/services/day_time_seconds.rb', line 20
def hours
number.to_f / 3600.0
end
|
#minutes ⇒ Object
16
17
18
|
# File 'app/services/day_time_seconds.rb', line 16
def minutes
number.to_f / 60.0
end
|
#seconds ⇒ Object
12
13
14
|
# File 'app/services/day_time_seconds.rb', line 12
def seconds
number.to_i
end
|
#to_s ⇒ Object
5
6
7
8
9
10
|
# File 'app/services/day_time_seconds.rb', line 5
def to_s
return '' unless number
hours, minutes_part = number.divmod(3600)
minutes, seconds_part = minutes_part.divmod(60)
[hours, minutes, seconds_part.round].map{|v| v.to_s.rjust(2, '0')}.join(':')
end
|