Class: Mp3::Album
Overview
This class presents an album, consisting of one of more physical media (LPs, CDs, tapes), each of which is referred to as a disc.
An instance of this class holds:
-
the name of the album’s artist;
-
the title of the album;
-
year of release;
-
and an array of Disc instances, each of which describes just one of the aforementioned physical media making up the album.
Instance Attribute Summary collapse
-
#album_artist ⇒ Object
Returns the value of attribute album_artist.
-
#album_title ⇒ Object
Returns the value of attribute album_title.
-
#album_year ⇒ Object
Returns the value of attribute album_year.
-
#discs ⇒ Object
readonly
Returns the value of attribute discs.
Instance Method Summary collapse
-
#add(item) ⇒ Object
This method is used to add a Disc instance to the [current] album instance.
-
#initialize(*args) ⇒ Album
constructor
The constructor takes a hash of symbols and their corresponding values.
-
#rename ⇒ Object
This method is used to rename the album and all of its contained discs to a consistent format.
- #update_id3_tags(dst_dir) ⇒ Object
- #write(dst_dir) ⇒ Object
Methods included from Utils::Parser
#parse_args, #parse_array, #parse_hash
Constructor Details
#initialize(*args) ⇒ Album
The constructor takes a hash of symbols and their corresponding values. Valid symbols are:
-
:artist => the name(s) of the artist(s) responsible for the album;
-
:title => the title of the album;
-
:year => the year of release.
If the :artist and/or :title symbols are not specified, they are derived from the grandparent and parent directories, respectively.
37 38 39 40 |
# File 'lib/mp3/album.rb', line 37 def initialize(*args) @discs = [] parse_args(nil, args) end |
Instance Attribute Details
#album_artist ⇒ Object
Returns the value of attribute album_artist.
23 24 25 |
# File 'lib/mp3/album.rb', line 23 def album_artist @album_artist end |
#album_title ⇒ Object
Returns the value of attribute album_title.
24 25 26 |
# File 'lib/mp3/album.rb', line 24 def album_title @album_title end |
#album_year ⇒ Object
Returns the value of attribute album_year.
25 26 27 |
# File 'lib/mp3/album.rb', line 25 def album_year @album_year end |
#discs ⇒ Object (readonly)
Returns the value of attribute discs.
26 27 28 |
# File 'lib/mp3/album.rb', line 26 def discs @discs end |
Instance Method Details
#add(item) ⇒ Object
This method is used to add a Disc instance to the [current] album instance. Assumptions
-
The order in which discs are appended is the disc play order.
47 48 49 50 51 52 |
# File 'lib/mp3/album.rb', line 47 def add(item) if item.class.name == Disc.name @discs << item end self end |
#rename ⇒ Object
This method is used to rename the album and all of its contained discs to a consistent format.
Right now:
-
the album level album title is left unchanged;
-
the disc level album titles are set to “Ddisc-number.number-of-discs” for all of the discs in the album;
-
the track level album titles are also set to “Ddisc-number.number-of-discs” for all of the discs in the album;
-
the tracks are renamed recursively (see the Track class for details).
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mp3/album.rb', line 65 def rename $track_number = 0 @discs.each do |disc| printf("Renaming disc %02d : ", disc.disc_number); $stdout.flush disc.album_artist = @album_artist disc.album_title = @album_title disc.album_year = @album_year disc.rename(discs.size) print "\n" end end |
#update_id3_tags(dst_dir) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/mp3/album.rb', line 90 def (dst_dir) here = Dir.pwd Dir.chdir dst_dir @discs.each do |disc| print "Updating ID3 tags for disc #{disc.disc_number}"; $stdout.flush disc. puts "" end Dir.chdir here end |
#write(dst_dir) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mp3/album.rb', line 79 def write(dst_dir) here = Dir.pwd Dir.chdir dst_dir @discs.each do |disc| printf("Copying disc %02d : ", disc.disc_number); $stdout.flush disc.write puts "" end Dir.chdir here end |