Class: Aggro::Message::Command

Inherits:
Struct
  • Object
show all
Defined in:
lib/aggro/message/command.rb

Overview

Public: Command message.

Constant Summary collapse

TYPE_CODE =
'03'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandee_idObject

Returns the value of attribute commandee_id

Returns:

  • (Object)

    the current value of commandee_id



4
5
6
# File 'lib/aggro/message/command.rb', line 4

def commandee_id
  @commandee_id
end

#detailsObject

Returns the value of attribute details

Returns:

  • (Object)

    the current value of details



4
5
6
# File 'lib/aggro/message/command.rb', line 4

def details
  @details
end

#senderObject

Returns the value of attribute sender

Returns:

  • (Object)

    the current value of sender



4
5
6
# File 'lib/aggro/message/command.rb', line 4

def sender
  @sender
end

Class Method Details

.parse(string) ⇒ Object



7
8
9
# File 'lib/aggro/message/command.rb', line 7

def self.parse(string)
  new string[2..37], string[38..73], parse_details(string[74..-1])
end

.parse_details(details) ⇒ Object



11
12
13
# File 'lib/aggro/message/command.rb', line 11

def self.parse_details(details)
  Marshal.load details
end

Instance Method Details

#argsObject



15
16
17
# File 'lib/aggro/message/command.rb', line 15

def args
  details[:args]
end

#command_classObject



19
20
21
# File 'lib/aggro/message/command.rb', line 19

def command_class
  ActiveSupport::Inflector.safe_constantize name
end

#nameObject



23
24
25
# File 'lib/aggro/message/command.rb', line 23

def name
  details[:name]
end

#to_commandObject



27
28
29
# File 'lib/aggro/message/command.rb', line 27

def to_command
  command_class.new args if command_class
end

#to_sObject



31
32
33
# File 'lib/aggro/message/command.rb', line 31

def to_s
  "#{TYPE_CODE}#{sender}#{commandee_id}#{Marshal.dump details}"
end