Class: Hallon::Playlist::Track
- Defined in:
- lib/hallon/playlist.rb
Overview
Playlist::Track is a Track with additional information attached to it, that is specific to the playlist it was created from. The returned track is a snapshot of the information, so even if the underlying track moves, this Playlist::Track will still contain the same information.
There is no way to refresh the information. You’ll have to retrieve the track again.
Instance Attribute Summary collapse
-
#added_at ⇒ Time?
readonly
Time when track at #index was added to playlist.
-
#adder ⇒ User?
readonly
Person who added track at #index to this playlist.
-
#index ⇒ Integer
readonly
Index this track was created with.
-
#message ⇒ String
readonly
Message attached to this track at #index.
-
#playlist_ptr ⇒ Spotify::Playlist
readonly
private
Playlist pointer this track was created from.
Attributes inherited from Track
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(pointer, playlist_pointer, index) ⇒ Track
constructor
A new instance of Track.
-
#moved? ⇒ Boolean
True if the track has not yet moved.
-
#playlist ⇒ Playlist
Playlist this track was created from.
-
#seen=(seen) ⇒ Playlist::Track
Set seen status of the Playlist::Track at the given index.
-
#seen? ⇒ Boolean
True if track at #index has been seen.
Methods inherited from Track
#_to_link, #album, #artist, #artists, #autolinked?, #availability, #available?, #disc, #duration, #from_link, #loaded?, local, #local?, #name, #offline_status, #placeholder?, #playable_track, #popularity, #starred=, #starred?, #status, #to_link, #unwrap
Methods included from Loadable
Methods included from Linkable
Methods inherited from Base
#==, from, from_link, #is_linkable?, #session, to_link, #to_pointer, #to_s
Constructor Details
#initialize(pointer, playlist_pointer, index) ⇒ Track
Returns a new instance of Track.
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/hallon/playlist.rb', line 27 def initialize(pointer, playlist_pointer, index) super(pointer) @index = index @playlist_ptr = playlist_pointer @message = Spotify.(playlist_ptr, index).to_s @seen = Spotify.playlist_track_seen(playlist_ptr, index) @added_at = Time.at(Spotify.playlist_track_create_time(playlist_ptr, index)).utc @adder = begin creator = Spotify.playlist_track_creator(playlist_ptr, index) User.from(creator) end end |
Instance Attribute Details
#added_at ⇒ Time? (readonly)
Returns time when track at #index was added to playlist.
50 51 52 |
# File 'lib/hallon/playlist.rb', line 50 def added_at @added_at end |
#adder ⇒ User? (readonly)
Returns person who added track at #index to this playlist.
53 54 55 |
# File 'lib/hallon/playlist.rb', line 53 def adder @adder end |
#index ⇒ Integer (readonly)
this value never changes, even if the original track is moved/removed
Returns index this track was created with.
47 48 49 |
# File 'lib/hallon/playlist.rb', line 47 def index @index end |
#message ⇒ String (readonly)
Returns message attached to this track at #index.
56 57 58 |
# File 'lib/hallon/playlist.rb', line 56 def @message end |
#playlist_ptr ⇒ Spotify::Playlist (readonly, private)
Returns playlist pointer this track was created from.
42 43 44 |
# File 'lib/hallon/playlist.rb', line 42 def playlist_ptr @playlist_ptr end |
Instance Method Details
#moved? ⇒ Boolean
Returns true if the track has not yet moved.
88 89 90 91 92 |
# File 'lib/hallon/playlist.rb', line 88 def moved? # using non-GC version deliberately; no need to keep a reference to # this pointer once we’re done here anyway Spotify.playlist_track(playlist_ptr, index) != pointer end |
#playlist ⇒ Playlist
Returns playlist this track was created from.
59 60 61 |
# File 'lib/hallon/playlist.rb', line 59 def playlist Playlist.new(playlist_ptr) end |
#seen=(seen) ⇒ Playlist::Track
Word of warning; this method will update the value you get from #seen?!
Set seen status of the Playlist::Track at the given index.
77 78 79 80 81 82 83 84 85 |
# File 'lib/hallon/playlist.rb', line 77 def seen=(seen) if moved? raise IndexError, "track has moved from #{index}" end error = Spotify.playlist_track_set_seen(playlist_ptr, index, !! seen) Error.maybe_raise(error) @seen = Spotify.playlist_track_seen(playlist_ptr, index) end |
#seen? ⇒ Boolean
Returns true if track at #index has been seen.
65 66 67 |
# File 'lib/hallon/playlist.rb', line 65 def seen? @seen end |