Class: TS3Query::TS3Connection
- Inherits:
-
Object
- Object
- TS3Query::TS3Connection
- Defined in:
- lib/ts3query/ts3_connection.rb
Direct Known Subclasses
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.
7 8 9 |
# File 'lib/ts3query/ts3_connection.rb', line 7 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
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 49 50 51 52 53 54 55 |
# File 'lib/ts3query/ts3_connection.rb', line 15 def method_missing(meth, *args, &block) result = [] = "" params = "" if block = QueryOptions.new yield ..each do |opt| += " -#{opt}" end end if args.first args.first.each do |key, value| params += " #{key}=#{value}" end end @connection.cmd("String" => "#{meth}#{params}#{}\r", "Match" => /error id=0 msg=ok\n/, "Timeout" => 3) { |data| data.force_encoding 'UTF-8' data.split("|").each do |current| current_data = {} current.split(" ").each do |entity| key, value = entity.split "=" current_data[key] = value 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
11 12 13 |
# File 'lib/ts3query/ts3_connection.rb', line 11 def disconnect @connection.close end |