Skip to content

Commit

Permalink
Using Track objects when importing a playlist.
Browse files Browse the repository at this point in the history
  • Loading branch information
ymendel committed Oct 8, 2008
1 parent 14a68c7 commit 6dcf18d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion lib/pj.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

require 'pj/playlist'
require 'pj/track'

module PJ
end
3 changes: 2 additions & 1 deletion lib/pj/playlist.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'plist'
require 'pj/track'

module PJ
class Playlist
Expand All @@ -19,7 +20,7 @@ def import(filename)
parsed_playlist = parsed['Playlists'].first
playlist = new
playlist.name = parsed_playlist['Name']
playlist.tracks = parsed_playlist['Playlist Items'].collect { |item| item['Track ID'] }
playlist.tracks = parsed_playlist['Playlist Items'].collect { |item| track = Track.new; track.track_id = item['Track ID']; track }
playlist
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/pj/track.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module PJ
class Track
attr_reader :track_id
attr_accessor :track_id
end
end
8 changes: 6 additions & 2 deletions spec/playlist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@
PJ::Playlist.import(@filename).name.should == @name
end

it 'should set the playlist tracks' do
PJ::Playlist.import(@filename).tracks.should == @track_ids
it 'should set the playlist tracks to track objects' do
PJ::Playlist.import(@filename).tracks.all? { |t| t.is_a?(PJ::Track) }.should == true
end

it 'should put the track objects in the order from the file' do
PJ::Playlist.import(@filename).tracks.collect { |t| t.track_id }.should == @track_ids
end
end
end
Expand Down

0 comments on commit 6dcf18d

Please sign in to comment.