lib/kagu/track.rb in kagu-0.3.0 vs lib/kagu/track.rb in kagu-0.3.1

- old
+ new

@@ -10,11 +10,11 @@ attr_reader :added_at, :album, :artist, :genre, :id, :length, :path, :title, :year def initialize(attributes = {}) super - raise Error.new("No such file: #{path.inspect}") unless File.file?(path) + raise Error.new("No such file: #{path.inspect}") if File.exists?(path) && !exists? end def <=>(other) return nil unless other.is_a?(self.class) added_at <=> other.added_at @@ -24,9 +24,13 @@ other.is_a?(self.class) && artist == other.artist && title == other.title && (length.to_i - other.length.to_i).abs < 3 end def eql?(other) super || self == other + end + + def exists? + File.file?(path) end def relative_path(directory) directory.present? && directory.starts_with?(directory) ? path.gsub(/\A#{Regexp.escape(directory)}\//, '') : path end