Class: MPDClient
- Inherits:
-
Object
- Object
- MPDClient
- Defined in:
- lib/mpd_client.rb,
lib/mpd_client/version.rb
Overview
The MPDClient library is used for interactions with a MPD.
Example
require 'mpd_client'
require 'logger'
client = MPDClient.new
client.log = Logger.new($stderr)
client.connect('/var/run/mpd/socket')
Constant Summary collapse
- VERSION =
"0.0.5"
Class Attribute Summary collapse
-
.log ⇒ Object
Default logger for all MPDClient instances.
Instance Attribute Summary collapse
-
#mpd_version ⇒ Object
readonly
Returns the value of attribute mpd_version.
Class Method Summary collapse
Instance Method Summary collapse
- #command_list_end ⇒ Object
- #command_list_ok_begin ⇒ Object
- #connect(host = 'localhost', port = 6600) ⇒ Object
- #disconnect ⇒ Object
-
#initialize ⇒ MPDClient
constructor
A new instance of MPDClient.
-
#log ⇒ Object
The current logger.
-
#log=(logger) ⇒ Object
Sets the
loggerused by this instance of MPDClient. - #reconnect ⇒ Object
Constructor Details
#initialize ⇒ MPDClient
Returns a new instance of MPDClient.
165 166 167 168 |
# File 'lib/mpd_client.rb', line 165 def initialize @mutex = Mutex.new reset end |
Class Attribute Details
.log ⇒ Object
Default logger for all MPDClient instances
MPDClient.log = Logger.new($stderr)
150 151 152 |
# File 'lib/mpd_client.rb', line 150 def log @log end |
Instance Attribute Details
#mpd_version ⇒ Object (readonly)
Returns the value of attribute mpd_version.
143 144 145 |
# File 'lib/mpd_client.rb', line 143 def mpd_version @mpd_version end |
Class Method Details
.add_command(name, retval) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/mpd_client.rb', line 152 def add_command(name, retval) escaped_name = name.gsub(' ', '_') define_method escaped_name.to_sym do |*args| execute(name, *args, retval) end end |
.remove_command(name) ⇒ Object
159 160 161 162 |
# File 'lib/mpd_client.rb', line 159 def remove_command(name) raise "Can't remove not existent '#{name}' command" unless method_defined? name.to_sym remove_method name.to_sym end |
Instance Method Details
#command_list_end ⇒ Object
200 201 202 203 204 205 |
# File 'lib/mpd_client.rb', line 200 def command_list_end raise "Not in command list" if @command_list.nil? write_command('command_list_end') return fetch_command_list end |
#command_list_ok_begin ⇒ Object
194 195 196 197 198 |
# File 'lib/mpd_client.rb', line 194 def command_list_ok_begin raise "Already in command list" unless @command_list.nil? write_command('command_list_ok_begin') @command_list = [] end |
#connect(host = 'localhost', port = 6600) ⇒ Object
170 171 172 173 174 |
# File 'lib/mpd_client.rb', line 170 def connect(host = 'localhost', port = 6600) @host = host @port = port reconnect end |
#disconnect ⇒ Object
187 188 189 190 191 |
# File 'lib/mpd_client.rb', line 187 def disconnect log.info("MPD disconnect") if log @socket.close reset end |
#log ⇒ Object
The current logger. If no logger has been set MPDClient.log is used
209 210 211 |
# File 'lib/mpd_client.rb', line 209 def log @log || MPDClient.log end |
#log=(logger) ⇒ Object
Sets the logger used by this instance of MPDClient
215 216 217 |
# File 'lib/mpd_client.rb', line 215 def log= logger @log = logger end |
#reconnect ⇒ Object
176 177 178 179 180 181 182 183 184 185 |
# File 'lib/mpd_client.rb', line 176 def reconnect log.info("MPD (re)connect #{@host}, #{@port}") if log if @host.start_with?('/') @socket = UNIXSocket.new(@host) hello else @socket = TCPSocket.new(@host, @port) hello end end |