Class: Notu::Track

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/notu/track.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Track

Returns a new instance of Track.



9
10
11
12
13
14
# File 'lib/notu/track.rb', line 9

def initialize(attributes = {})
  attributes = attributes.stringify_keys
  self.artist = attributes['artist']
  self.plays_count = attributes['plays_count']
  self.title = attributes['title']
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



7
8
9
# File 'lib/notu/track.rb', line 7

def artist
  @artist
end

#plays_countObject

Returns the value of attribute plays_count.



7
8
9
# File 'lib/notu/track.rb', line 7

def plays_count
  @plays_count
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/notu/track.rb', line 7

def title
  @title
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
19
20
# File 'lib/notu/track.rb', line 16

def <=>(other)
  return nil unless other.is_a?(Track)
  result = (artist <=> other.artist)
  result.zero? ? (title <=> other.title) : result
end

#==(other) ⇒ Object



22
23
24
# File 'lib/notu/track.rb', line 22

def ==(other)
  other.is_a?(self.class) && artist == other.artist && title == other.title
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/notu/track.rb', line 26

def eql?(other)
  super || self == other
end

#to_sObject



30
31
32
# File 'lib/notu/track.rb', line 30

def to_s
  "#{artist} - #{title}"
end