Class: SmartFox::Packet
- Inherits:
-
Object
- Object
- SmartFox::Packet
- Defined in:
- lib/smartfox/packet.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#room ⇒ Object
readonly
Returns the value of attribute room.
Class Method Summary collapse
- .parse(data) ⇒ Object
- .parse_json(data) ⇒ Object
- .parse_string(data) ⇒ Object
- .parse_xml(data) ⇒ Object
Instance Method Summary collapse
-
#initialize(header, action, room = 0, extra = nil) ⇒ Packet
constructor
A new instance of Packet.
Constructor Details
#initialize(header, action, room = 0, extra = nil) ⇒ Packet
Returns a new instance of Packet.
6 7 8 9 10 11 |
# File 'lib/smartfox/packet.rb', line 6 def initialize(header, action, room = 0, extra = nil) @header = header @action = action @room = room @extra = extra end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
4 5 6 |
# File 'lib/smartfox/packet.rb', line 4 def action @action end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/smartfox/packet.rb', line 4 def data @data end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/smartfox/packet.rb', line 4 def header @header end |
#room ⇒ Object (readonly)
Returns the value of attribute room.
4 5 6 |
# File 'lib/smartfox/packet.rb', line 4 def room @room end |
Class Method Details
.parse(data) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/smartfox/packet.rb', line 13 def self.parse(data) case data[0, 1] when '<' return parse_xml(data) when '{' return parse_json(data) else return parse_string(data) end end |
.parse_json(data) ⇒ Object
34 35 36 |
# File 'lib/smartfox/packet.rb', line 34 def self.parse_json(data) SmartFox::Logger.debug "SmartFox::Packet#parse_json('#{data}')" end |
.parse_string(data) ⇒ Object
38 39 40 |
# File 'lib/smartfox/packet.rb', line 38 def self.parse_string(data) SmartFox::Logger.debug "SmartFox::Packet#parse_string('#{data}')" end |
.parse_xml(data) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/smartfox/packet.rb', line 24 def self.parse_xml(data) SmartFox::Logger.debug "SmartFox::Packet#parse_xml('#{data}')" document = LibXML::XML::Parser.string(data).parse header = document.root['t'] action = document.root.child['action'] room = document.root.child['r'] extra = document.root.child.child new(header, action, room, extra) end |