Class: EM::Pusher::Client::MsgParser

Inherits:
Object
  • Object
show all
Defined in:
lib/em/pusher/client/msg_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(msg) ⇒ MsgParser

Returns a new instance of MsgParser.



7
8
9
# File 'lib/em/pusher/client/msg_parser.rb', line 7

def initialize(msg)
  @msg = msg
end

Instance Method Details

#dataObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/em/pusher/client/msg_parser.rb', line 30

def data
  @data =
    if json['data'].is_a?(String)
      JSON.parse(json['data'])
    else
      json['data']
    end
rescue JSON::ParserError
  {}
end

#eventObject



11
12
13
14
# File 'lib/em/pusher/client/msg_parser.rb', line 11

def event
  return '{}' unless json
  @event ||= json['event']
end

#jsonObject



24
25
26
27
28
# File 'lib/em/pusher/client/msg_parser.rb', line 24

def json
  @json ||= JSON.parse(@msg.data)
rescue JSON::ParserError
  {}
end

#to_sObject



16
17
18
# File 'lib/em/pusher/client/msg_parser.rb', line 16

def to_s
  @msg.to_s
end

#typeObject



20
21
22
# File 'lib/em/pusher/client/msg_parser.rb', line 20

def type
  @msg.type
end