Class: Kagu::Track

Inherits:
Object
  • Object
show all
Includes:
Comparable, AttributesInitializer
Defined in:
lib/kagu/track.rb

Constant Summary collapse

MANDATORY_ATTRIBUTES =
%w(added_at id length).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributesInitializer

#initialize

Instance Attribute Details

#added_atObject

Returns the value of attribute added_at.



10
11
12
# File 'lib/kagu/track.rb', line 10

def added_at
  @added_at
end

#albumObject

Returns the value of attribute album.



10
11
12
# File 'lib/kagu/track.rb', line 10

def album
  @album
end

#artistObject

Returns the value of attribute artist.



10
11
12
# File 'lib/kagu/track.rb', line 10

def artist
  @artist
end

#bpmObject

Returns the value of attribute bpm.



10
11
12
# File 'lib/kagu/track.rb', line 10

def bpm
  @bpm
end

#genreObject

Returns the value of attribute genre.



10
11
12
# File 'lib/kagu/track.rb', line 10

def genre
  @genre
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/kagu/track.rb', line 10

def id
  @id
end

#lengthObject

Returns the value of attribute length.



10
11
12
# File 'lib/kagu/track.rb', line 10

def length
  @length
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/kagu/track.rb', line 10

def path
  @path
end

#titleObject

Returns the value of attribute title.



10
11
12
# File 'lib/kagu/track.rb', line 10

def title
  @title
end

#yearObject

Returns the value of attribute year.



10
11
12
# File 'lib/kagu/track.rb', line 10

def year
  @year
end

Instance Method Details

#<=>(other) ⇒ Object



12
13
14
15
# File 'lib/kagu/track.rb', line 12

def <=>(other)
  return nil unless other.is_a?(self.class)
  length <=> other.length
end

#==(other) ⇒ Object



17
18
19
# File 'lib/kagu/track.rb', line 17

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/kagu/track.rb', line 21

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

#exists_on_disk?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/kagu/track.rb', line 25

def exists_on_disk?
  path.present? && path.file?
end

#hashObject



29
30
31
# File 'lib/kagu/track.rb', line 29

def hash
  [artist, title].hash
end

#to_sObject



33
34
35
# File 'lib/kagu/track.rb', line 33

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