Class: Musictree::Album
- Inherits:
-
Object
- Object
- Musictree::Album
- Includes:
- Enumerable
- Defined in:
- lib/musictree/album.rb
Overview
Album contains the tracks of an album. It is an Enumerable for the tracks An Album has a title.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.scan(path) ⇒ Album
Scans in the music files that sit in the album path.
Instance Method Summary collapse
- #[](idx) ⇒ Object
-
#album? ⇒ Boolean
An album is an album.
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(path, preliminary_name) ⇒ Album
constructor
A new instance of Album.
- #inspect ⇒ Object
- #scan_album ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(path, preliminary_name) ⇒ Album
Returns a new instance of Album.
21 22 23 24 25 |
# File 'lib/musictree/album.rb', line 21 def initialize(path, preliminary_name) @title = preliminary_name @path = path @tracks = [] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/musictree/album.rb', line 10 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
10 11 12 |
# File 'lib/musictree/album.rb', line 10 def title @title end |
Class Method Details
.scan(path) ⇒ Album
Scans in the music files that sit in the album path. (No subdirs)
15 16 17 18 19 |
# File 'lib/musictree/album.rb', line 15 def self.scan(path) preliminary_name = File.basename(File.dirname(path)) moi = new(path, preliminary_name) moi.scan_album end |
Instance Method Details
#[](idx) ⇒ Object
35 36 37 |
# File 'lib/musictree/album.rb', line 35 def [](idx) @tracks[idx] end |
#album? ⇒ Boolean
An album is an album
48 49 50 |
# File 'lib/musictree/album.rb', line 48 def album? true end |
#each(&block) ⇒ Object
27 28 29 |
# File 'lib/musictree/album.rb', line 27 def each(&block) @tracks.each(&block) end |
#empty? ⇒ Boolean
31 32 33 |
# File 'lib/musictree/album.rb', line 31 def empty? @tracks.empty? end |
#inspect ⇒ Object
43 44 45 |
# File 'lib/musictree/album.rb', line 43 def inspect @tracks.map(&:inspect) end |
#scan_album ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/musictree/album.rb', line 52 def scan_album files = Dir[File.join(@path, "*.{m3u,wav,flac,mp3,opus,aiff}")] if files.empty? # is it a collection? return Tree.scan(@path) end @tracks = files.map do |path| Track.new(path) end if @tracks.all?(&:track) @tracks = @tracks.sort_by(&:track) end titles = @tracks.map(&:album).uniq @title = titles.first self end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/musictree/album.rb', line 39 def to_s @tracks.map(&:to_s) end |