notu 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/notu/track.rb +8 -0
- data/spec/notu/track_spec.rb +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 736588600308397cd4deb396c9dc11ea5cf86118
|
4
|
+
data.tar.gz: 2f608f7c398c92b398da5123dd33acff628bda23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c430f8ce22d57ac19f59050854dfa2cc7a99a08aacfedeffa3860ebbab636b133260cbc89f29d99e596955125b257617926b2c1d65ff69a0d7bce5f2f4f98462
|
7
|
+
data.tar.gz: 460e6b724d50508d3bfe44184d66ab616002e9db8c4473a7118e35ab6fcc84cfb8b22408cbce17a1fe0303d4f8a13160ffb2b30e92b4ed36648c80071048e4d6
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/lib/notu/track.rb
CHANGED
@@ -2,6 +2,8 @@ module Notu
|
|
2
2
|
|
3
3
|
class Track
|
4
4
|
|
5
|
+
include Comparable
|
6
|
+
|
5
7
|
attr_reader :artist, :plays_count, :title
|
6
8
|
|
7
9
|
def initialize(attributes = {})
|
@@ -11,6 +13,12 @@ module Notu
|
|
11
13
|
self.title = attributes['title']
|
12
14
|
end
|
13
15
|
|
16
|
+
def <=>(other)
|
17
|
+
return nil unless other.is_a?(Track)
|
18
|
+
result = (artist <=> other.artist)
|
19
|
+
result.zero? ? (title <=> other.title) : result
|
20
|
+
end
|
21
|
+
|
14
22
|
def ==(other)
|
15
23
|
other.is_a?(self.class) && artist == other.artist && title == other.title
|
16
24
|
end
|
data/spec/notu/track_spec.rb
CHANGED
@@ -4,6 +4,29 @@ describe Notu::Track do
|
|
4
4
|
|
5
5
|
let(:track) { Notu::Track.new(artist: 'Serial Killaz', title: 'Good Enough') }
|
6
6
|
|
7
|
+
describe '#<=>' do
|
8
|
+
|
9
|
+
let(:other) { track.dup }
|
10
|
+
|
11
|
+
it 'compares track by artist' do
|
12
|
+
expect {
|
13
|
+
allow(other).to receive(:artist).and_return('Technimatic')
|
14
|
+
}.to change { track <=> other }.from(0).to(-1)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'compares track by artist and then by title' do
|
18
|
+
expect {
|
19
|
+
allow(other).to receive(:title).and_return('Send Dem')
|
20
|
+
}.to change { track <=> other }.from(0).to(-1)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns nil if given track is not a track' do
|
24
|
+
expect(track <=> nil).to be_nil
|
25
|
+
expect(track <=> 'foo').to be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
7
30
|
describe '#==' do
|
8
31
|
|
9
32
|
let(:other) { track.dup }
|