Class: Turntabler::Playlist
- Defined in:
- lib/turntabler/playlist.rb
Overview
Represents a collection of songs managed by the user and that can be played within a room
Instance Attribute Summary collapse
-
#active ⇒ Boolean
readonly
Whether this is the currently active playlist.
-
#id ⇒ String
readonly
Allow the id to be set via the “name” attribute.
-
#songs ⇒ Array<Turntabler::Song>
readonly
The songs that have been added to this playlist.
Instance Method Summary collapse
-
#activate ⇒ true
Changes this playlist to be used for queueing new songs with the room.
-
#delete ⇒ true
Permanently deletes this playlist and the list of songs within it.
-
#load(options = {}) ⇒ true
Loads the attributes for this playlist.
-
#song(song_id) ⇒ Turntabler::Song
Gets the song with the given id.
-
#update(attributes = {}) ⇒ true
Updates this playlist’s information.
Methods inherited from Resource
#==, attribute, #attributes=, #hash, #initialize, #loaded?, #pretty_print, #pretty_print_instance_variables
Methods included from Assertions
#assert_valid_keys, #assert_valid_values
Methods included from DigestHelpers
Constructor Details
This class inherits a constructor from Turntabler::Resource
Instance Attribute Details
#active ⇒ Boolean (readonly)
Whether this is the currently active playlist
14 |
# File 'lib/turntabler/playlist.rb', line 14 attribute :active, :load => false |
#id ⇒ String (readonly)
Allow the id to be set via the “name” attribute
10 |
# File 'lib/turntabler/playlist.rb', line 10 attribute :id, :name, :load => false |
#songs ⇒ Array<Turntabler::Song> (readonly)
The songs that have been added to this playlist
18 19 20 |
# File 'lib/turntabler/playlist.rb', line 18 attribute :songs, :list do |songs| songs.map {|attrs| Song.new(client, attrs.merge(:playlist => id))} end |
Instance Method Details
#activate ⇒ true
Changes this playlist to be used for queueing new songs with the room.
77 78 79 80 81 |
# File 'lib/turntabler/playlist.rb', line 77 def activate api('playlist.switch') self.attributes = {'active' => true} true end |
#delete ⇒ true
Permanently deletes this playlist and the list of songs within it. If this is the currently active playlist, the “default” playlist will become active.
90 91 92 93 |
# File 'lib/turntabler/playlist.rb', line 90 def delete api('playlist.delete') true end |
#load(options = {}) ⇒ true
Loads the attributes for this playlist. Attributes will automatically load when accessed, but this allows data to be forcefully loaded upfront.
32 33 34 35 36 37 38 39 |
# File 'lib/turntabler/playlist.rb', line 32 def load( = {}) assert_valid_keys(, :minimal) = {:minimal => false}.merge() data = api('playlist.all', ) self.attributes = data super() end |
#song(song_id) ⇒ Turntabler::Song
Gets the song with the given id.
102 103 104 |
# File 'lib/turntabler/playlist.rb', line 102 def song(song_id) songs.detect {|song| song.id == song_id} end |
#update(attributes = {}) ⇒ true
Updates this playlist’s information.
50 51 52 53 54 55 56 57 58 |
# File 'lib/turntabler/playlist.rb', line 50 def update(attributes = {}) assert_valid_keys(attributes, :id) # Update id id = attributes.delete(:id) update_id(id) if id true end |