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.6"
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
logger
used by this instance of MPDClient. - #reconnect ⇒ Object
Constructor Details
#initialize ⇒ MPDClient
Returns a new instance of MPDClient.
163 164 165 166 |
# File 'lib/mpd_client.rb', line 163 def initialize @mutex = Mutex.new reset end |
Class Attribute Details
.log ⇒ Object
Default logger for all MPDClient instances
MPDClient.log = Logger.new($stderr)
148 149 150 |
# File 'lib/mpd_client.rb', line 148 def log @log end |
Instance Attribute Details
#mpd_version ⇒ Object (readonly)
Returns the value of attribute mpd_version.
141 142 143 |
# File 'lib/mpd_client.rb', line 141 def mpd_version @mpd_version end |
Class Method Details
.add_command(name, retval) ⇒ Object
150 151 152 153 154 155 |
# File 'lib/mpd_client.rb', line 150 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
157 158 159 160 |
# File 'lib/mpd_client.rb', line 157 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
198 199 200 201 202 203 |
# File 'lib/mpd_client.rb', line 198 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
192 193 194 195 196 |
# File 'lib/mpd_client.rb', line 192 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
168 169 170 171 172 |
# File 'lib/mpd_client.rb', line 168 def connect(host = 'localhost', port = 6600) @host = host @port = port reconnect end |
#disconnect ⇒ Object
185 186 187 188 189 |
# File 'lib/mpd_client.rb', line 185 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
207 208 209 |
# File 'lib/mpd_client.rb', line 207 def log @log || MPDClient.log end |
#log=(logger) ⇒ Object
Sets the logger
used by this instance of MPDClient
213 214 215 |
# File 'lib/mpd_client.rb', line 213 def log= logger @log = logger end |
#reconnect ⇒ Object
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/mpd_client.rb', line 174 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 |