class Playlist

Data model class that for a single playlist.

Constants

VERSION

The version number of the Playlist Ruby gem

Attributes

creator[RW]

The name of the creator of this playlist @return [String]

description[RW]

A description/annotation/synopsis of the playlist @return [String]

identifiers[R]

Get a hash of identifier for this playlist Identifiers can either be Strings or URIs @return [Hash] an hash of identifiers

image[RW]

URI of an image associated with this playlist @return [String]

info_url[RW]

A URL to get more inforamtion about this playlist @return [String]

license[RW]

A link to the license / terms of use for this playlist @return [String]

media_location[RW]

A URI (or filename) to the location of the media Use this if the playlist is a single file @return [String]

title[RW]

The title of the playlist @return [String]

tracks[R]

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

new(attr = {}) { |self| ... } click to toggle source

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_track(args) click to toggle source

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_start_times() click to toggle source

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
duration() click to toggle source

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