Class: Kagu::Track
- Inherits:
-
Object
- Object
- Kagu::Track
- Includes:
- Comparable, AttributesInitializer
- Defined in:
- lib/kagu/track.rb
Constant Summary collapse
- MANDATORY_ATTRIBUTES =
%w(added_at id length path)- IS_MAC_OS =
RUBY_PLATFORM =~ /darwin/
Instance Attribute Summary collapse
-
#added_at ⇒ Object
readonly
Returns the value of attribute added_at.
-
#album ⇒ Object
readonly
Returns the value of attribute album.
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#genre ⇒ Object
readonly
Returns the value of attribute genre.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Track
constructor
A new instance of Track.
- #relative_path(directory) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Track
Returns a new instance of Track.
13 14 15 16 |
# File 'lib/kagu/track.rb', line 13 def initialize(attributes = {}) super raise Error.new("No such file: #{path.inspect}") if File.exists?(path) && !exists? end |
Instance Attribute Details
#added_at ⇒ Object
Returns the value of attribute added_at.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def added_at @added_at end |
#album ⇒ Object
Returns the value of attribute album.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def album @album end |
#artist ⇒ Object
Returns the value of attribute artist.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def artist @artist end |
#genre ⇒ Object
Returns the value of attribute genre.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def genre @genre end |
#id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def id @id end |
#length ⇒ Object
Returns the value of attribute length.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def length @length end |
#path ⇒ Object
Returns the value of attribute path.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def path @path end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def title @title end |
#year ⇒ Object
Returns the value of attribute year.
11 12 13 |
# File 'lib/kagu/track.rb', line 11 def year @year end |
Instance Method Details
#<=>(other) ⇒ Object
18 19 20 21 |
# File 'lib/kagu/track.rb', line 18 def <=>(other) return nil unless other.is_a?(self.class) added_at <=> other.added_at end |
#==(other) ⇒ Object
23 24 25 |
# File 'lib/kagu/track.rb', line 23 def ==(other) other.is_a?(self.class) && artist == other.artist && title == other.title && (length.to_i - other.length.to_i).abs < 3 end |
#eql?(other) ⇒ Boolean
27 28 29 |
# File 'lib/kagu/track.rb', line 27 def eql?(other) super || self == other end |
#exists? ⇒ Boolean
31 32 33 |
# File 'lib/kagu/track.rb', line 31 def exists? File.file?(path) end |
#relative_path(directory) ⇒ Object
35 36 37 |
# File 'lib/kagu/track.rb', line 35 def relative_path(directory) directory.present? && directory.starts_with?(directory) ? path.gsub(/\A#{Regexp.escape(directory)}\//, '') : path end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/kagu/track.rb', line 39 def to_s "#{artist} - #{title}" end |