mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
31 lines
602 B
Ruby
31 lines
602 B
Ruby
require './models/mpd_connection'
|
|
|
|
class Album
|
|
attr_accessor :title, :genre, :year
|
|
|
|
def initialize(album)
|
|
first_song = MPDConnection.mpd.search(:album, album).first
|
|
@title = first_song.album
|
|
@genre = first_song.genre
|
|
@year = first_song.date
|
|
end
|
|
|
|
def <=>(album)
|
|
year <=> album.year
|
|
end
|
|
|
|
def self.all
|
|
MPDConnection.mpd.albums.sort.map { |artist| Album.new(album) }
|
|
end
|
|
|
|
def self.by_artist(artist)
|
|
MPDConnection.mpd.albums(artist).map { |album| Album.new(album) }
|
|
end
|
|
|
|
def attributes
|
|
{ title: @title,
|
|
genre: @genre,
|
|
year: @year }
|
|
end
|
|
end
|