From d4f3afb5b966430ccff4030833435cd3ad499df5 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 21 Jul 2009 18:58:08 -0700 Subject: Remove redundant code with split_and_hash method. --- mpdlib.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/mpdlib.rb b/mpdlib.rb index 70eb016..12d2d3d 100644 --- a/mpdlib.rb +++ b/mpdlib.rb @@ -102,13 +102,24 @@ class MPD return send_request 'clear' end - # Not yet complete. - def playlistinfo - playlist = send_request 'playlistinfo' - playlist = playlist.split(/(?!\n)(?=file:)/).map do |song| + def split_and_hash str + songs = str.split(/(?!\n)(?=file:)/).map do |song| generate_hash song end - return playlist + return songs + end + + # Not yet complete. + def playlistinfo + return split_and_hash send_request 'playlistinfo' + end + + def find type, what + return split_and_hash send_request 'find %s "%s"' % [type, what] + end + + def search type, what + return split_and_hash send_request 'search %s "%s"' % [type, what] end end -- cgit v1.2.3-70-g09d2