Class: Muzak::Song
Instance Attribute Summary collapse
-
#album ⇒ Object
readonly
Returns the value of attribute album.
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#genre ⇒ Object
readonly
Returns the value of attribute genre.
-
#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.
-
#track ⇒ Object
readonly
Returns the value of attribute track.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #best_guess_album_art ⇒ Object
- #full_title ⇒ Object
-
#initialize(path) ⇒ Song
constructor
A new instance of Song.
Methods included from Utils
#album_art?, #debug, #debug?, #error, #fail_arity, #info, #music?, #output, #pretty, #verbose, #verbose?, #warn, #warn_arity
Constructor Details
#initialize(path) ⇒ Song
Returns a new instance of Song.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/muzak/song.rb', line 9 def initialize(path) @path = path TagLib::FileRef.open(path) do |ref| break if ref.null? @title = ref.tag.title @artist = ref.tag.artist @album = ref.tag.album @year = ref.tag.year @track = ref.tag.track @genre = ref.tag.genre @comment = ref.tag.comment @length = ref.audio_properties.length end # provide some sane fallbacks @title ||= File.basename(path, File.extname(path)) rescue "" @track ||= 0 # we'll need to sort by track number end |
Instance Attribute Details
#album ⇒ Object (readonly)
Returns the value of attribute album.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def album @album end |
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def artist @artist end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def comment @comment end |
#genre ⇒ Object (readonly)
Returns the value of attribute genre.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def genre @genre end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def length @length end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def title @title end |
#track ⇒ Object (readonly)
Returns the value of attribute track.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def track @track end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
7 8 9 |
# File 'lib/muzak/song.rb', line 7 def year @year end |
Instance Method Details
#==(other) ⇒ Object
44 45 46 |
# File 'lib/muzak/song.rb', line 44 def ==(other) path == other.path end |
#best_guess_album_art ⇒ Object
29 30 31 32 33 34 |
# File 'lib/muzak/song.rb', line 29 def best_guess_album_art album_dir = File.dirname(path) art = Dir.entries(album_dir).find { |ent| album_art?(ent) } File.join(album_dir, art) unless art.nil? end |
#full_title ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/muzak/song.rb', line 36 def full_title full = title.dup full << " by #{artist}" if artist full << " on #{album}" if album full end |