Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added status command

  • Loading branch information...
commit 5d83e6e5f2add818d75edff00375adbbd3e27657 1 parent 820c47f
Michał Krzyżanowski krzyzak authored

Showing 2 changed files with 18 additions and 0 deletions. Show diff stats Hide diff stats

  1. +13 0 lib/mpc.rb
  2. +5 0 test/mpc_test.rb
13 lib/mpc.rb
@@ -73,4 +73,17 @@ def get_response
73 73 end
74 74 response
75 75 end
  76 +
  77 + def to_hash(string)
  78 + output = Hash.new
  79 + string.each_line do |line|
  80 + key, value = line.chomp.split(": ", 2)
  81 + output[key.to_sym] = value
  82 + end
  83 + output
  84 + end
  85 +
  86 + def status
  87 + to_hash(send_command("status"))
  88 + end
76 89 end
5 test/mpc_test.rb
@@ -27,4 +27,9 @@ def test_gets_outputs_empty_string_on_OK_response
27 27 @mpc.stubs(:gets_from_socket).returns("OK\n")
28 28 assert_equal("", @mpc.stop )
29 29 end
  30 +
  31 + def test_status_outputs_propper_hash
  32 + @mpc.stubs(:get_response).returns("volume: -1\nrepeat: 0\nrandom: 0\nsingle: 0\nconsume: 0\nplaylist: 43\nplaylistlength: 41\nxfade: 0\nstate: stop\nsong: 17\nsongid: 17\nnextsong: 18\nnextsongid: 18\n")
  33 + assert_equal({:songid=>"17", :state=>"stop", :single=>"0", :volume=>"-1", :nextsong=>"18", :consume=>"0", :nextsongid=>"18", :playlist=>"43", :repeat=>"0", :song=>"17", :playlistlength=>"41", :random=>"0", :xfade=>"0"}, @mpc.send(:status) )
  34 + end
30 35 end

0 comments on commit 5d83e6e

Please sign in to comment.
Something went wrong with that request. Please try again.