Class: Elrec::Indexer

Inherits:
Object
  • Object
show all
Defined in:
lib/elrec/indexer.rb

Instance Method Summary collapse

Constructor Details

#initialize(host = "localhost", port = 1056) ⇒ Indexer

Returns a new instance of Indexer.



6
7
8
9
10
# File 'lib/elrec/indexer.rb', line 6

def initialize(host = "localhost", port = 1056)
  @host = host
  @port = port
  self.connect
end

Instance Method Details

#closeObject



23
24
25
26
# File 'lib/elrec/indexer.rb', line 23

def close
  @socket.write("\n")
  @socket.close
end

#connectObject



12
13
14
# File 'lib/elrec/indexer.rb', line 12

def connect
  @socket = TCPSocket.open(@host, @port)
end

#index(user_id, item_id) ⇒ Object



16
17
18
19
20
21
# File 'lib/elrec/indexer.rb', line 16

def index(user_id, item_id)
  json = "{'userId' : #{user_id}, " +
          "'itemId' : #{item_id}}\n"
  @socket.write(json)
  return @socket.gets
end