Class: Weskit::MP::Adapter
Instance Attribute Summary collapse
-
#buffer ⇒ Object
Returns the value of attribute buffer.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#socket ⇒ Object
Returns the value of attribute socket.
Instance Method Summary collapse
-
#initialize(connection, debug = false) ⇒ Adapter
constructor
A new instance of Adapter.
- #message(container, hash) ⇒ Object
- #read ⇒ Object
- #write(object) ⇒ Object
Constructor Details
#initialize(connection, debug = false) ⇒ Adapter
Returns a new instance of Adapter.
7 8 9 10 11 |
# File 'lib/weskit/mp/adapter.rb', line 7 def initialize connection, debug = false @connection = connection @debug = debug @parser = :simple end |
Instance Attribute Details
#buffer ⇒ Object
Returns the value of attribute buffer.
5 6 7 |
# File 'lib/weskit/mp/adapter.rb', line 5 def buffer @buffer end |
#parser ⇒ Object
Returns the value of attribute parser.
5 6 7 |
# File 'lib/weskit/mp/adapter.rb', line 5 def parser @parser end |
#socket ⇒ Object
Returns the value of attribute socket.
5 6 7 |
# File 'lib/weskit/mp/adapter.rb', line 5 def socket @socket end |
Instance Method Details
#message(container, hash) ⇒ Object
13 14 15 16 |
# File 'lib/weskit/mp/adapter.rb', line 13 def container, hash msg = {container => hash} write msg end |
#read ⇒ Object
18 19 20 21 22 23 |
# File 'lib/weskit/mp/adapter.rb', line 18 def read size = @connection.socket.read(4).unpack('N').first data = StringIO.new @connection.socket.read(size) read_nodes data end |
#write(object) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/weskit/mp/adapter.rb', line 25 def write object case object when Hash then write_hash object when String then write_string object end end |