Class: Weskit::MP::Adapter

Inherits:
Object show all
Defined in:
lib/weskit/mp/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bufferObject

Returns the value of attribute buffer.



5
6
7
# File 'lib/weskit/mp/adapter.rb', line 5

def buffer
  @buffer
end

#parserObject

Returns the value of attribute parser.



5
6
7
# File 'lib/weskit/mp/adapter.rb', line 5

def parser
  @parser
end

#socketObject

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 message container, hash
  msg = {container => hash}
  write msg
end

#readObject



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