Class: Elrec::Indexer
- Inherits:
-
Object
- Object
- Elrec::Indexer
- Defined in:
- lib/elrec/indexer.rb
Instance Method Summary collapse
- #close ⇒ Object
- #connect ⇒ Object
- #index(user_id, item_id) ⇒ Object
-
#initialize(host = "localhost", port = 1056) ⇒ Indexer
constructor
A new instance of Indexer.
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
#close ⇒ Object
23 24 25 26 |
# File 'lib/elrec/indexer.rb', line 23 def close @socket.write("\n") @socket.close end |
#connect ⇒ Object
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 |