Class: MPD::Client::Connection
- Inherits:
-
Object
- Object
- MPD::Client::Connection
- Defined in:
- lib/mpd/client/connection.rb
Overview
It’s Client‘s internal class. Don’t use it outside Client
Instance Method Summary collapse
- #connect ⇒ Object
- #disconnect ⇒ Object
- #gets ⇒ Object
-
#initialize(host:, port:) ⇒ Connection
constructor
A new instance of Connection.
- #puts(text) ⇒ Object
Constructor Details
#initialize(host:, port:) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 |
# File 'lib/mpd/client/connection.rb', line 9 def initialize(host:, port:) @host = host @port = port end |
Instance Method Details
#connect ⇒ Object
14 15 16 17 |
# File 'lib/mpd/client/connection.rb', line 14 def connect disconnect if socket @socket = TCPSocket.open(host, port) end |
#disconnect ⇒ Object
19 20 21 22 |
# File 'lib/mpd/client/connection.rb', line 19 def disconnect socket && socket.close @socket = nil end |
#gets ⇒ Object
29 30 31 32 |
# File 'lib/mpd/client/connection.rb', line 29 def gets raise ConnectionError unless socket socket.gets end |
#puts(text) ⇒ Object
24 25 26 27 |
# File 'lib/mpd/client/connection.rb', line 24 def puts(text) raise ConnectionError unless socket socket.puts(text) end |