Class: Beans::BeanCounter
- Inherits:
-
Object
- Object
- Beans::BeanCounter
- Defined in:
- lib/beans/bean_counter.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(opts = {}) ⇒ BeanCounter
constructor
A new instance of BeanCounter.
- #open ⇒ Object
- #query(query = 'dollars') ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ BeanCounter
Returns a new instance of BeanCounter.
4 5 6 7 |
# File 'lib/beans/bean_counter.rb', line 4 def initialize(opts={}) opts[:port] ||= Config.port @port = opts[:port] end |
Instance Method Details
#close ⇒ Object
21 22 23 |
# File 'lib/beans/bean_counter.rb', line 21 def close @socket.close end |
#open ⇒ Object
9 10 11 |
# File 'lib/beans/bean_counter.rb', line 9 def open @socket = TCPSocket.new('127.0.0.1', @port) end |
#query(query = 'dollars') ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/beans/bean_counter.rb', line 13 def query( query='dollars' ) self.open @socket.puts query response = @socket.gets self.close response end |