summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2009-07-21 15:50:04 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2009-07-21 15:50:04 -0700
commitff0ff2ac54d47123088c6819b62a2f72a7f61166 (patch)
tree615a5f695deffc1cbffdb5c8a45d5ff2a1f1d345
parent36d8e7b37af77beb9718dbf292425085c29b83ca (diff)
downloadruby-libmpd-ff0ff2ac54d47123088c6819b62a2f72a7f61166.tar.gz
ruby-libmpd-ff0ff2ac54d47123088c6819b62a2f72a7f61166.tar.xz
Remove redundant code with generate_hash method.
-rw-r--r--mpdlib.rb29
1 files changed, 8 insertions, 21 deletions
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