sandro-metamuse 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/History CHANGED
@@ -1,3 +1,6 @@
1
+ 0.1.3 07/19/2009
2
+ * Artist controls validity and whether or not to use #best_guess
3
+
1
4
  0.1.2 07/18/2009
2
5
  * Modified Cracks date parser, queries for Radiohead now work
3
6
  * Ruby 1.9 compatibility
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -18,6 +18,10 @@ module Metamuse
18
18
  super
19
19
  end
20
20
 
21
+ def best_guess
22
+ invalid? ? similar_artists.first : self
23
+ end
24
+
21
25
  def tracks
22
26
  @tracks ||= albums.map{|a| a.tracks}.flatten
23
27
  end
@@ -44,6 +48,14 @@ module Metamuse
44
48
  "#<#{self.class.inspect}:#{object_id.inspect}, name: #{name.inspect}, albums: #{album_names.inspect}>"
45
49
  end
46
50
 
51
+ def valid?
52
+ ! invalid?
53
+ end
54
+
55
+ def invalid?
56
+ @invalid
57
+ end
58
+
47
59
  private
48
60
 
49
61
  def album_names
@@ -11,7 +11,7 @@ module Metamuse
11
11
  end
12
12
 
13
13
  def self.artist(name)
14
- attributes = artist_info(name).best_guess.attributes.rename_key(:url, :lastfm_url)
14
+ attributes = artist_info(name).attributes.rename_key(:url, :lastfm_url)
15
15
  ::Metamuse::Artist.new attributes
16
16
  end
17
17
 
@@ -26,10 +26,6 @@ class Metamuse::Services::Lastfm::Artist
26
26
  end
27
27
  alias image= images=
28
28
 
29
- def best_guess
30
- valid? ? self : similar_artists.first
31
- end
32
-
33
29
  def similar_artists=(attrs={})
34
30
  attrs['artist'].each do |artist_attrs|
35
31
  @similar_artists << self.class.new(artist_attrs)
@@ -42,6 +38,11 @@ class Metamuse::Services::Lastfm::Artist
42
38
  @listeners = stats['listeners']
43
39
  end
44
40
 
41
+ def url=(url)
42
+ @url = url
43
+ @invalid = ! valid?
44
+ end
45
+
45
46
  def valid?
46
47
  url !~ %r(/music/\+noredirect/)
47
48
  end
data/metamuse.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{metamuse}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sandro Turriate"]
12
- s.date = %q{2009-08-15}
12
+ s.date = %q{2009-08-16}
13
13
  s.email = %q{sandro.turriate@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
@@ -1,8 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
3
  describe Metamuse::Artist do
4
- subject { Metamuse::Artist.new :name => 'Mozart' }
5
-
6
4
  describe ".build_artist" do
7
5
  subject { Metamuse::Artist }
8
6
  it "gets and enhances freebase artist information" do
@@ -14,6 +12,18 @@ describe Metamuse::Artist do
14
12
  end
15
13
  end
16
14
 
15
+ subject { Metamuse::Artist.new :name => 'Mozart' }
16
+
17
+ describe "#invalid?" do
18
+ it "declares new artists are valid by default" do
19
+ subject.should_not be_invalid
20
+ end
21
+
22
+ it "is invalid when built with an invalid flag" do
23
+ Metamuse::Artist.new(:invalid => true).should be_invalid
24
+ end
25
+ end
26
+
17
27
  describe "#tracks" do
18
28
  it "collects all of the tracks from the every album" do
19
29
  album1 = fake(:tracks => [1,2])
@@ -96,4 +106,18 @@ describe Metamuse::Artist do
96
106
  subject.tracks.should == freebase_artist.tracks
97
107
  end
98
108
  end
109
+
110
+ describe "#best_guess" do
111
+ it "returns itself when the artist is valid" do
112
+ mock(subject).invalid? { false }
113
+ subject.best_guess.should == subject
114
+ end
115
+
116
+ it "returns the most similar artist when the artist is invalid" do
117
+ similar_artist = fake(:similar_artist)
118
+ mock(subject).similar_artists { [similar_artist] }
119
+ mock(subject).invalid? { true }
120
+ subject.best_guess.should == similar_artist
121
+ end
122
+ end
99
123
  end
@@ -3,20 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
3
3
  describe Metamuse::Services::Lastfm::Artist do
4
4
  subject { Metamuse::Services::Lastfm::Artist }
5
5
 
6
- describe "#best_guess" do
7
- it "returns itself when the artist is valid" do
8
- artist = subject.new :url => 'http://last.fm/music/Coldplay'
9
- artist.best_guess.should == artist
10
- end
11
-
12
- it "returns the most similar artist when the artist is invalid" do
13
- similar_artist = fake(:similar_artist)
14
- artist = subject.new :url => 'http://last.fm/music/+noredirect/Cold Play'
15
- mock(artist).similar_artists { [similar_artist] }
16
- artist.best_guess.should == similar_artist
17
- end
18
- end
19
-
20
6
  describe "#valid?" do
21
7
  it "is an invalid artist when the url contains '+noredirect'" do
22
8
  artist = subject.new :url => 'http://last.fm/music/+noredirect/Cold Play'
@@ -28,4 +14,17 @@ describe Metamuse::Services::Lastfm::Artist do
28
14
  artist.should be_valid
29
15
  end
30
16
  end
17
+
18
+ describe "#url=" do
19
+ it "sets the url instance variable" do
20
+ artist = subject.new(:url => 'http://something.com')
21
+ artist.instance_variable_get(:@url).should == 'http://something.com'
22
+ artist.url.should == 'http://something.com'
23
+ end
24
+
25
+ it "sets the invalid instance variable" do
26
+ artist = subject.new(:url => 'http://last.fm/music/+noredirect/Cold Play')
27
+ artist.should_not be_valid
28
+ end
29
+ end
31
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sandro-metamuse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Turriate
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-15 00:00:00 -07:00
12
+ date: 2009-08-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15