Class: EM::Pusher::Client::MsgParser
- Inherits:
-
Object
- Object
- EM::Pusher::Client::MsgParser
- Defined in:
- lib/em/pusher/client/msg_parser.rb
Instance Method Summary collapse
- #data ⇒ Object
- #event ⇒ Object
-
#initialize(msg) ⇒ MsgParser
constructor
A new instance of MsgParser.
- #json ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
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
#data ⇒ Object
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 |
#event ⇒ Object
11 12 13 14 |
# File 'lib/em/pusher/client/msg_parser.rb', line 11 def event return '{}' unless json @event ||= json['event'] end |
#json ⇒ Object
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_s ⇒ Object
16 17 18 |
# File 'lib/em/pusher/client/msg_parser.rb', line 16 def to_s @msg.to_s end |
#type ⇒ Object
20 21 22 |
# File 'lib/em/pusher/client/msg_parser.rb', line 20 def type @msg.type end |