class Notu::Track
Attributes
artist[R]
plays_count[R]
title[R]
Public Class Methods
new(attributes = {})
click to toggle source
# 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
Public Instance Methods
<=>(other)
click to toggle source
# 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)
click to toggle source
# File lib/notu/track.rb, line 22 def ==(other) other.is_a?(self.class) && artist == other.artist && title == other.title end
eql?(other)
click to toggle source
Calls superclass method
# File lib/notu/track.rb, line 26 def eql?(other) super || self == other end
to_s()
click to toggle source
# File lib/notu/track.rb, line 30 def to_s "#{artist} - #{title}" end
Private Instance Methods
artist=(value)
click to toggle source
# File lib/notu/track.rb, line 36 def artist=(value) @artist = value.to_s.squish.presence || raise(Error.new("#{self.class}#artist must be specified, #{value.inspect} given")) end
plays_count=(value)
click to toggle source
# File lib/notu/track.rb, line 40 def plays_count=(value) @plays_count = value.is_a?(Integer) || value.is_a?(String) && value =~ /\A[0-9]+\z/ ? [0, value.to_i].max : nil end
title=(value)
click to toggle source
# File lib/notu/track.rb, line 44 def title=(value) @title = value.to_s.squish.presence || raise(Error.new("#{self.class}#title must be specified, #{value.inspect} given")) end