Class: MPD::Protocol::Error

Inherits:
Response show all
Defined in:
lib/mpd/protocol/response.rb

Constant Summary collapse

Codes =
{
  NOT_LIST:   1,
  ARG:        2,
  PASSWORD:   3,
  PERMISSION: 4,
  UNKNOWN:    5,

  NO_EXIST:       50,
  PLAYLIST_MAX:   51,
  SYSTEM:         52,
  PLAYLIST_LOAD:  53,
  UPDATE_ALREADY: 54,
  PLAYER_SYNC:    55,
  EXIST:          56
}

Instance Attribute Summary collapse

Attributes inherited from Response

#command

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#each, #empty?, read, #to_a, #to_hash

Constructor Details

#initialize(command, data, code, offset, command_name, message) ⇒ Error

Returns a new instance of Error.



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/mpd/protocol/response.rb', line 154

def initialize (command, data, code, offset, command_name, message)
  if !command_name.empty? && command.name != command_name.to_sym
    raise ArgumentError, 'the passed command object and the response command name do not match'
  end

  super(command, data)

  @code    = (code.is_a?(Integer) || Integer(code) rescue false) ? Codes.key(code.to_i) : code.to_sym.upcase
  @offset  = offset.to_i
  @message = message

  unless Codes[to_sym]
    raise ArgumentError, 'the Error code does not exist'
  end
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



152
153
154
# File 'lib/mpd/protocol/response.rb', line 152

def message
  @message
end

#offsetObject (readonly)

Returns the value of attribute offset.



152
153
154
# File 'lib/mpd/protocol/response.rb', line 152

def offset
  @offset
end

Class Method Details

.parse(text) ⇒ Object



148
149
150
# File 'lib/mpd/protocol/response.rb', line 148

def self.parse (text)
  text.match(/^\[(\d+)@(\d+)\] {([^}]*)} (.*?)$/).to_a[1 .. -1]
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


170
# File 'lib/mpd/protocol/response.rb', line 170

def success?; false; end

#to_iObject



176
177
178
# File 'lib/mpd/protocol/response.rb', line 176

def to_i
  Codes[to_sym]
end

#to_symObject



172
173
174
# File 'lib/mpd/protocol/response.rb', line 172

def to_sym
  @code
end