Class: RBus::Auth::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/rbus/auth/state_machine.rb

Overview

Parses server response and splits it into component parts Decodes where appropriate (only DATA)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Command

Returns a new instance of Command.



158
159
160
161
# File 'lib/rbus/auth/state_machine.rb', line 158

def initialize(string)
  @command, data = string.split(/ /, 2)
  @data = (@command == 'DATA') ? hex_decode(data) : data
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



157
158
159
# File 'lib/rbus/auth/state_machine.rb', line 157

def command
  @command
end

#dataObject (readonly)

Returns the value of attribute data.



157
158
159
# File 'lib/rbus/auth/state_machine.rb', line 157

def data
  @data
end

Instance Method Details

#hex_decode(encoded) ⇒ Object



163
164
165
# File 'lib/rbus/auth/state_machine.rb', line 163

def hex_decode(encoded)
  encoded.scan(/[[:xdigit:]]{2}/).map{|h|h.hex.chr}.join
end