class TrackList::TimeConverter
A helper class to convert an audio track's length in seconds to a more readable format.
Public Class Methods
new(time)
click to toggle source
Pass in an integer of seconds to this class.
# File lib/track_list/time_converter.rb, line 9 def initialize(time) @time = time end
Public Instance Methods
format_time()
click to toggle source
This method formats the time into a readable format. See: www.codethought.com/2010/01/seconds-minutes-hours-converting-time-units-in-ruby/
# 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