class MPD::Commands::Abstract
Base class for MPD
commands.
Attributes
connection[R]
Public Class Methods
new(connection: nil, host: 'localhost', port: 6600)
click to toggle source
You can provide you own connection. It should have same
# File lib/mpd/commands/abstract.rb, line 16 def initialize(connection: nil, host: 'localhost', port: 6600) @connection = if connection connection else Connection.new(host: host, port: port) .tap(&:connect) .tap(&:gets) end end
Public Instance Methods
execute(command)
click to toggle source
This method should be overriden. Example:
def execute super('ping') end
# File lib/mpd/commands/abstract.rb, line 34 def execute(command) exec_command(command) end
Private Instance Methods
exec_command(command)
click to toggle source
# File lib/mpd/commands/abstract.rb, line 40 def exec_command(command) connection.puts(command) response = ServerResponse.from_connection(connection) raise(MpdError, response.status) if response.error? response end
exec_command_list(commands)
click to toggle source
# File lib/mpd/commands/abstract.rb, line 47 def exec_command_list(commands) connection.puts('command_list_begin') commands.each { |c| connection.puts(c) } connection.puts('command_list_end') response = ServerResponse.from_connection(connection) raise(MpdError, response.status) if response.error? response end
resolve_range(arg)
click to toggle source
# File lib/mpd/commands/abstract.rb, line 57 def resolve_range(arg) if arg.is_a?(Range) last = arg.exclude_end? ? arg.end : arg.end + 1 "#{arg.begin}:#{last}" else arg end end