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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11523174d4da71857b5513c36837279183caef99
4
- data.tar.gz: a1b805725c15928fe56d8023ca3223227673c30b
3
+ metadata.gz: 736588600308397cd4deb396c9dc11ea5cf86118
4
+ data.tar.gz: 2f608f7c398c92b398da5123dd33acff628bda23
5
5
  SHA512:
6
- metadata.gz: 2dd627d18abd7c655fea935afae8e278258dd093349e7716b7acdda6d402465af302037138b0d2621762db57e3fdb634de1079b892d08b4f414c243e569b6c37
7
- data.tar.gz: 17636f649d3ba7aa29b304ee8241b9eb4fc6a37abdc9330bd303d35acbfdb566042e84743f859043183f7ae272493462da5d554c25d65d77505f10bd3a9a4e62
6
+ metadata.gz: c430f8ce22d57ac19f59050854dfa2cc7a99a08aacfedeffa3860ebbab636b133260cbc89f29d99e596955125b257617926b2c1d65ff69a0d7bce5f2f4f98462
7
+ data.tar.gz: 460e6b724d50508d3bfe44184d66ab616002e9db8c4473a7118e35ab6fcc84cfb8b22408cbce17a1fe0303d4f8a13160ffb2b30e92b4ed36648c80071048e4d6
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
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
@@ -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 }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Toulotte