1
0
mirror of https://github.com/danbee/mpd-client synced 2025-03-04 08:39:09 +00:00
mpd-client/lib/mpd_client/album.rb
2013-12-12 11:51:59 +00:00

49 lines
767 B
Ruby

module MPDClient
class Album
include ClassToProc
include Enumerable
extend Forwardable
delegate %i(artist genre) => :@first_song
def initialize(album)
@songs = MPDClient::Song.by(album: album)
@first_song = @songs.first
end
def each(&block)
@songs.each(&block)
end
def title
@first_song.album
end
def year
@first_song.year
end
def to_h
{
title: title,
artist: artist,
genre: genre,
year: year,
songs: self.map(&:to_h)
}
end
class << self
def all
MPDClient.conn.albums.sort.map(&self)
end
def by_artist(artist)
MPDClient.conn.albums(artist).map(&self)
end
end
end
end