Class: Soundcloud9000::Models::TrackCollection
- Inherits:
-
Collection
- Object
- Collection
- Soundcloud9000::Models::TrackCollection
- Defined in:
- lib/soundcloud9000/models/track_collection.rb
Overview
This model deals with the different types of tracklists that populate the tracklist section
Constant Summary collapse
- DEFAULT_LIMIT =
50
Instance Attribute Summary collapse
-
#collection_to_load ⇒ Object
Returns the value of attribute collection_to_load.
-
#help ⇒ Object
Returns the value of attribute help.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#playlist ⇒ Object
Returns the value of attribute playlist.
-
#shuffle ⇒ Object
Returns the value of attribute shuffle.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes inherited from Collection
Instance Method Summary collapse
- #clear_and_replace ⇒ Object
- #favorites_tracks ⇒ Object
-
#initialize(client) ⇒ TrackCollection
constructor
A new instance of TrackCollection.
- #load ⇒ Object
- #load_more ⇒ Object
- #playlist_tracks ⇒ Object
- #recent_tracks ⇒ Object
- #size ⇒ Object
- #user_tracks ⇒ Object
Methods inherited from Collection
#[], #append, #clear, #each, #replace
Constructor Details
#initialize(client) ⇒ TrackCollection
Returns a new instance of TrackCollection.
15 16 17 18 19 20 21 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 15 def initialize(client) super @limit = DEFAULT_LIMIT @collection_to_load = :recent @shuffle = false @help = false end |
Instance Attribute Details
#collection_to_load ⇒ Object
Returns the value of attribute collection_to_load.
13 14 15 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 13 def collection_to_load @collection_to_load end |
#help ⇒ Object
Returns the value of attribute help.
13 14 15 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 13 def help @help end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
12 13 14 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 12 def limit @limit end |
#playlist ⇒ Object
Returns the value of attribute playlist.
13 14 15 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 13 def playlist @playlist end |
#shuffle ⇒ Object
Returns the value of attribute shuffle.
13 14 15 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 13 def shuffle @shuffle end |
#user ⇒ Object
Returns the value of attribute user.
13 14 15 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 13 def user @user end |
Instance Method Details
#clear_and_replace ⇒ Object
27 28 29 30 31 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 27 def clear_and_replace clear load_more events.trigger(:replace) end |
#favorites_tracks ⇒ Object
47 48 49 50 51 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 47 def favorites_tracks return [] if @client.current_user.nil? @client.get(@client.current_user.uri + '/favorites', offset: @limit * @page, limit: @limit) end |
#load ⇒ Object
33 34 35 36 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 33 def load clear load_more end |
#load_more ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 38 def load_more unless @loaded tracks = send(@collection_to_load.to_s + '_tracks') @loaded = true if tracks.empty? append tracks.map { |hash| Track.new hash } @page += 1 end end |
#playlist_tracks ⇒ Object
69 70 71 72 73 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 69 def playlist_tracks return [] if @playlist.nil? @client.get(@playlist.uri + '/tracks', offset: @limit * @page, limit: @limit) end |
#recent_tracks ⇒ Object
53 54 55 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 53 def recent_tracks @client.get('/tracks', offset: @page * limit, limit: @limit) end |
#size ⇒ Object
23 24 25 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 23 def size @rows.size end |
#user_tracks ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/soundcloud9000/models/track_collection.rb', line 57 def user_tracks return [] if @client.current_user.nil? user_tracks = @client.get(@client.current_user.uri + '/tracks', offset: @limit * @page, limit: @limit) if user_tracks.empty? UI::Input.error("'#{@client.current_user.username}' has not authored any tracks. Use f to switch to their favorites, or s to switch to their playlists.") return [] else return user_tracks end end |