Skip to content

Commit

Permalink
Album.artist should always return a Scrobbler::Artist object
Browse files Browse the repository at this point in the history
  • Loading branch information
xhochy committed Aug 11, 2010
1 parent 684d113 commit ad4c7e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions lib/scrobbler/album.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def initialize(data={})
raise ArgumentError unless data.kind_of?(Hash)
super(data)

if @artist.is_a?(String) then
@artist = Artist.new(:name => @artist)
end

raise ArgumentError, "Artist or mbid is required" if @artist.nil? && @mbid.nil?
raise ArgumentError, "Name is required" if @name.empty?
end
Expand Down Expand Up @@ -74,8 +78,7 @@ def load_from_xml(node)
next unless tag.name == 'tag'
@top_tags << Tag.new_from_libxml(tag)
end
when 'wiki'
# @todo Handle wiki entries
when 'wiki' # @todo Handle wiki entries
when 'text'
# ignore, these are only blanks
when '#text'
Expand Down Expand Up @@ -107,7 +110,7 @@ def load_from_xml(node)
# @todo Add language code for wiki translation
def load_info
return nil if @info_loaded
xml = Base.request('album.getinfo', {:artist => @artist, :album => @name})
xml = Base.request('album.getinfo', {:artist => @artist.name, :album => @name})
unless xml.root['status'] == 'failed'
xml.root.children.each do |childL1|
next unless childL1.name == 'album'
Expand Down
2 changes: 1 addition & 1 deletion scrobbler-ng.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |s|

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["John Nunemaker", "Jonathan Rudenberg", "Uwe L. Korn"]
s.date = %q{2010-08-05}
s.date = %q{2010-08-06}
s.description = %q{A ruby library for accessing the Last.fm 2.0 API. It is higly optimized so that it uses less memory and parses XML (through Nokogiri) than other implementations.}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
Expand Down
2 changes: 1 addition & 1 deletion test/unit/album_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

it 'should know the artist' do
@album.artist.should eql('Carrie Underwood')
@album.artist.name.should eql('Carrie Underwood')
end

it "should know it's name" do
Expand Down

0 comments on commit ad4c7e0

Please sign in to comment.