Class: TrackList::TimeConverter
- Inherits:
-
Object
- Object
- TrackList::TimeConverter
- Defined in:
- lib/track_list/time_converter.rb
Overview
A helper class to convert an audio track’s length in seconds to a more readable format.
Instance Method Summary collapse
-
#format_time ⇒ Object
This method formats the time into a readable format.
-
#initialize(time) ⇒ TimeConverter
constructor
Pass in an integer of seconds to this class.
Constructor Details
#initialize(time) ⇒ TimeConverter
Pass in an integer of seconds to this class.
9 10 11 |
# File 'lib/track_list/time_converter.rb', line 9 def initialize(time) @time = time end |
Instance Method Details
#format_time ⇒ Object
This method formats the time into a readable format. See: www.codethought.com/2010/01/seconds-minutes-hours-converting-time-units-in-ruby/
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/track_list/time_converter.rb', line 16 def format_time # Find the seconds. seconds = @time % 60 # Find the minutes. minutes = (@time / 60) % 60 # Find the hours. hours = (@time / 3600) # Format the time. return hours.to_s + ":" + format("%02d", minutes.to_s) + ":" + format("%02d", seconds.to_s) end |