class Sc20XX::Models::TrackCollection

This model deals with the different types of tracklists that populate the tracklist section

Constants

DEFAULT_LIMIT

Attributes

collection_to_load[RW]
limit[R]
playlist[RW]
user[RW]

Public Class Methods

new(client) click to toggle source
Calls superclass method Sc20XX::Models::Collection::new
# File lib/sc20XX/models/track_collection.rb, line 15
def initialize(client)
  super
  @limit = DEFAULT_LIMIT
  @collection_to_load = :recent
end

Public Instance Methods

clear_and_replace() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 25
def clear_and_replace
  clear
  load_more
  events.trigger(:replace)
end
favorites_tracks() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 45
def favorites_tracks
  return [] if @client.current_user.nil?
  @client.get(@client.current_user.uri + '/favorites', offset: @limit * @page, limit: @limit)
end
load() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 31
def load
  clear
  load_more
end
load_more() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 36
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() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 65
def playlist_tracks
  return [] if @playlist.nil?
  @client.get(@playlist.uri + '/tracks', offset: @limit * @page, limit: @limit)
end
recent_tracks() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 50
def recent_tracks
  @client.get('/tracks', offset: @page * limit, limit: @limit)
end
size() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 21
def size
  @rows.size
end
user_tracks() click to toggle source
# File lib/sc20XX/models/track_collection.rb, line 54
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