Class: Playlist
- Inherits:
-
Object
- Object
- Playlist
- Defined in:
- lib/playlist.rb,
lib/playlist/version.rb
Overview
Data model class that for a single playlist.
Defined Under Namespace
Modules: Format Classes: Contributor, Track
Constant Summary collapse
- VERSION =
The version number of the Playlist Ruby gem
'1.2.0'
Instance Attribute Summary collapse
-
#creator ⇒ String
The name of the creator of this playlist.
-
#description ⇒ String
A description/annotation/synopsis of the playlist.
-
#identifiers ⇒ Hash
readonly
Get a hash of identifier for this playlist Identifiers can either be Strings or URIs.
-
#image ⇒ String
URI of an image associated with this playlist.
-
#info_url ⇒ String
A URL to get more inforamtion about this playlist.
-
#license ⇒ String
A link to the license / terms of use for this playlist.
-
#media_location ⇒ String
A URI (or filename) to the location of the media Use this if the playlist is a single file.
-
#title ⇒ String
The title of the playlist.
-
#tracks ⇒ Array<Track>
readonly
Get the array that contains the list of track for this playlist.
Instance Method Summary collapse
-
#add_track(args) ⇒ Object
Add a track to the playlist.
-
#calculate_start_times ⇒ Object
Calculate the start track times based on the duration.
-
#duration ⇒ Integer, Float
Get the total duration of this playlist in milliseconds If any tracks on the playlist don’t have a duation, then they are ignored.
-
#initialize(attr = {}) {|_self| ... } ⇒ Playlist
constructor
Create a new Playlist.
Constructor Details
#initialize(attr = {}) {|_self| ... } ⇒ Playlist
Create a new Playlist
45 46 47 48 49 50 51 52 53 |
# 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 |
Instance Attribute Details
#creator ⇒ String
The name of the creator of this playlist
11 12 13 |
# File 'lib/playlist.rb', line 11 def creator @creator end |
#description ⇒ String
A description/annotation/synopsis of the playlist
15 16 17 |
# File 'lib/playlist.rb', line 15 def description @description end |
#identifiers ⇒ Hash (readonly)
Get a hash of identifier for this playlist Identifiers can either be Strings or URIs
37 38 39 |
# File 'lib/playlist.rb', line 37 def identifiers @identifiers end |
#image ⇒ String
URI of an image associated with this playlist
32 33 34 |
# File 'lib/playlist.rb', line 32 def image @image end |
#info_url ⇒ String
A URL to get more inforamtion about this playlist
24 25 26 |
# File 'lib/playlist.rb', line 24 def info_url @info_url end |
#license ⇒ String
A link to the license / terms of use for this playlist
28 29 30 |
# File 'lib/playlist.rb', line 28 def license @license end |
#media_location ⇒ String
A URI (or filename) to the location of the media Use this if the playlist is a single file
20 21 22 |
# File 'lib/playlist.rb', line 20 def media_location @media_location end |
#title ⇒ String
The title of the playlist
7 8 9 |
# File 'lib/playlist.rb', line 7 def title @title end |
#tracks ⇒ Array<Track> (readonly)
Get the array that contains the list of track for this playlist
41 42 43 |
# File 'lib/playlist.rb', line 41 def tracks @tracks end |
Instance Method Details
#add_track(args) ⇒ Object
Add a track to the playlist
58 59 60 |
# File 'lib/playlist.rb', line 58 def add_track(args) @tracks << (args.is_a?(Track) ? args : Track.new(args)) end |
#calculate_start_times ⇒ Object
Calculate the start track times based on the duration. This method will only overwrite the start times, if not set
71 72 73 74 75 76 77 78 79 |
# 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 ⇒ Integer, Float
Get the total duration of this playlist in milliseconds If any tracks on the playlist don’t have a duation, then they are ignored
65 66 67 |
# File 'lib/playlist.rb', line 65 def duration @tracks.map(&:duration).compact.inject(:+) end |