Class: TS3Connection
- Inherits:
-
Object
- Object
- TS3Connection
- Defined in:
- lib/ts3query/ts3_connection.rb
Instance Method Summary collapse
- #disconnect ⇒ Object
-
#initialize(params) ⇒ TS3Connection
constructor
A new instance of TS3Connection.
- #method_missing(meth, *args, &block) ⇒ Object
Constructor Details
#initialize(params) ⇒ TS3Connection
Returns a new instance of TS3Connection.
4 5 6 |
# File 'lib/ts3query/ts3_connection.rb', line 4 def initialize(params) connect(params) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ts3query/ts3_connection.rb', line 12 def method_missing(meth, *args, &block) result = [] = "" params = "" if block = QueryOptions.new yield ..each do |opt| += " -#{opt}" end end args.each do |param| params += " #{param.keys[0]}=#{param[param.keys[0]]}" end @connection.cmd("String" => "#{meth}#{params}#{}\r", "Match" => /error id=0 msg=ok\n/, "Timeout" => 3) { |data| data.split("|").each do |current| current_data = {} current.split(" ").each do |entity| current_data[entity.split("=")[0]] = entity.split("=")[1] end current_data.delete("error") current_data.delete("id") current_data.delete("msg") result << current_data end } result << {"id" => "0", "msg" => "ok"} result.delete({}) result end |
Instance Method Details
#disconnect ⇒ Object
8 9 10 |
# File 'lib/ts3query/ts3_connection.rb', line 8 def disconnect @connection.close end |