From ff0ff2ac54d47123088c6819b62a2f72a7f61166 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 21 Jul 2009 15:50:04 -0700 Subject: Remove redundant code with generate_hash method. --- mpdlib.rb | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'mpdlib.rb') diff --git a/mpdlib.rb b/mpdlib.rb index 4519787..e1d3332 100644 --- a/mpdlib.rb +++ b/mpdlib.rb @@ -37,11 +37,10 @@ class MPD end end - def currentsong - response = send_request('currentsong') + def generate_hash str hash = Hash.new - response.split("\n").each do |line| + str.split("\n").each do |line| field, value = line.split(': ') hash[field] = value end @@ -49,27 +48,15 @@ class MPD return hash end - def status - response = send_request('status') - hash = Hash.new - - response.split("\n").each do |line| - field, value = line.split(': ') - hash[field] = value - end + def currentsong + return generate_hash send_request 'currentsong' + end - return hash + def status + return generate_hash send_request 'status' end def stats - response = send_request('stats') - hash = Hash.new - - response.split("\n").each do |line| - field, value = line.split(': ') - hash[field] = value - end - - return hash + return generate_hash send_request 'stats' end end -- cgit v1.2.3-70-g09d2