Class: Bluecap::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/bluecap/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Message

Initialize a Message with data.

data - The String JSON message to parse.



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

def initialize(data)
  @data = MultiJson.load(data, symbolize_keys: true)
end

Instance Method Details

#contentsObject

The contents of the message.

Examples

message = Message.new('{"identify": "Evelyn"}')
message.contents
# => "Evelyn"

Returns the contents of the message; the data type is different based on the contents of the message.



34
35
36
# File 'lib/bluecap/message.rb', line 34

def contents
  @data.first[1]
end

#recipientObject

The signature of the handler that should respond to the message.

Examples

message = Message.new('{"identify": "Evelyn"}')
message.recipient
# => :identify

Returns the Symbol recipient of the messsage.



20
21
22
# File 'lib/bluecap/message.rb', line 20

def recipient
  @data.first[0].to_sym if @data.first
end