class Playlist
Data model class that for a single playlist.
Constants
- VERSION
The version number of the
Playlist
Ruby gem
Attributes
The name of the creator of this playlist @return [String]
A description/annotation/synopsis of the playlist @return [String]
Get a hash of identifier for this playlist Identifiers can either be Strings or URIs @return [Hash] an hash of identifiers
URI of an image associated with this playlist @return [String]
A URL to get more inforamtion about this playlist @return [String]
A link to the license / terms of use for this playlist @return [String]
A URI (or filename) to the location of the media Use this if the playlist is a single file @return [String]
The title of the playlist @return [String]
Get the array that contains the list of track for this playlist @return [Array<Track>] an array of tracks in the playlist
Public Class Methods
Create a new Playlist
@param attr [Hash] a hash of attibute values to set
# File lib/playlist.rb, line 45 def initialize(attr = {}) @tracks = [] @identifiers = {} attr.each_pair do |key, value| send("#{key}=", value) end yield(self) if block_given? end
Public Instance Methods
Add a track to the playlist @param args [Track, Hash] either a Track
object or
a Hash of attributes to creatre a new Track
# File lib/playlist.rb, line 58 def add_track(args) @tracks << (args.is_a?(Track) ? args : Track.new(args)) end
Calculate the start track times based on the duration. This method will only overwrite the start times, if not set
# File lib/playlist.rb, line 71 def calculate_start_times time = tracks.first.start_time || 0 tracks.each do |track| break if track.duration.nil? time = (track.start_time ||= time) time += track.duration end end
Get the total duration of this playlist in milliseconds If any tracks on the playlist don't have a duation, then they are ignored @return [Integer, Float]
# File lib/playlist.rb, line 65 def duration @tracks.map(&:duration).compact.inject(:+) end