class MonkeyMusic::Generate::ToplistLoader
Attributes
loaded_toplists[R]
Public Class Methods
new(toplist_file)
click to toggle source
# File lib/monkey_music_generate/toplist_loader.rb, line 7 def initialize(toplist_file) @toplist_file = toplist_file @toplists = {} @loaded_toplists = {} end
Public Instance Methods
load_for_user!(user)
click to toggle source
# File lib/monkey_music_generate/toplist_loader.rb, line 13 def load_for_user!(user) @user = user # Load toplists URI:s from file self.instance_eval(IO.read @toplist_file) # Load toplist contents from libspotify load_toplists! end
Private Instance Methods
load_album(album)
click to toggle source
# File lib/monkey_music_generate/toplist_loader.rb, line 62 def load_album(album) artist = album.artist.load MonkeyMusic::Metadata::Album.new :name => album.name, :artist => artist.name, :year => album.release_year end
load_artist(artist)
click to toggle source
# File lib/monkey_music_generate/toplist_loader.rb, line 69 def load_artist(artist) MonkeyMusic::Metadata::Artist.new :name => artist.name end
load_from_list(type, uri)
click to toggle source
# File lib/monkey_music_generate/toplist_loader.rb, line 41 def load_from_list(type, uri) playlist = Hallon::Playlist.new(uri).load tracks = playlist.tracks.to_a tracks.each(&:load) if type == :tracks tracks elsif type == :artists tracks.map(&:artist).each(&:load) elsif type == :albums tracks.map(&:album).each(&:load) end end
load_toplists!()
click to toggle source
Toplist loading
# File lib/monkey_music_generate/toplist_loader.rb, line 31 def load_toplists! @toplists.each do |name, list| @loaded_toplists[name] = { :type => list[:type], :items => load_from_list(list[:type], list[:uri]) } @user.toplists[name] = parse_toplist(list[:type], @loaded_toplists[name][:items]) end end
load_track(track)
click to toggle source
# File lib/monkey_music_generate/toplist_loader.rb, line 73 def load_track(track) album = track.album.load artist = track.artist.load MonkeyMusic::Metadata::Track.new :uri => track.to_link.to_str, :name => track.name, :artist => artist.name, :album => album.name, :year => album.release_year end
parse_toplist(type, list)
click to toggle source
# File lib/monkey_music_generate/toplist_loader.rb, line 54 def parse_toplist(type, list) case type when :tracks then list.map { |track| load_track track } when :albums then list.map { |album| load_album album } when :artists then list.map { |artist| load_artist artist } end end
toplist(type, name, uri)
click to toggle source
User
toplist DSL
# File lib/monkey_music_generate/toplist_loader.rb, line 25 def toplist(type, name, uri) @toplists[name] = { :type => type, :uri => uri } end