mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Add song class.
This commit is contained in:
parent
2e884a8e30
commit
067669d62b
15
models/song.rb
Normal file
15
models/song.rb
Normal file
@ -0,0 +1,15 @@
|
||||
require './models/mpd_connection'
|
||||
|
||||
class Song < Struct.new(:artist, :album, :title)
|
||||
|
||||
def initialize(song)
|
||||
@song = song
|
||||
self.artist = song.artist
|
||||
self.album = song.album
|
||||
self.title = song.title
|
||||
end
|
||||
|
||||
def self.queue
|
||||
MPDConnection.mpd.queue.map { |song| self.new(song) }
|
||||
end
|
||||
end
|
||||
16
spec/models/song_spec.rb
Normal file
16
spec/models/song_spec.rb
Normal file
@ -0,0 +1,16 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Song do
|
||||
|
||||
let(:song1) { MPD::Song.new({ title: 'Back in Black', album: 'Back in Black', genre: 'Rock', date: '1980' }) }
|
||||
let(:song2) { MPD::Song.new({ title: 'Highway to Hell', album: 'Highway to Hell', genre: 'Rock', date: '1979' }) }
|
||||
|
||||
before do
|
||||
MPDConnection.mpd.stub(:queue).and_return([song1, song2])
|
||||
end
|
||||
|
||||
it 'returns the queue of songs' do
|
||||
queue = Song.queue
|
||||
expect(queue).to have(2).items
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user