Class: GameDig::QueryResult

Inherits:
Object
  • Object
show all
Defined in:
lib/game_dig/query_result.rb

Overview

Typed container for a normalized GameDig server response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ QueryResult

Returns a new instance of QueryResult.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/game_dig/query_result.rb', line 33

def initialize(hash)
  @name        = hash['name']
  @map         = hash['map']
  @password    = hash['password']
  @num_players = hash['num_players']
  @max_players = hash['max_players']
  @players     = hash['players'] || []
  @bots        = hash['bots'] || []
  @connect     = hash['connect']
  @ping        = hash['ping']
  @query_port  = hash['query_port']
  @version     = hash['version']
  @raw         = hash['raw'] || {}
end

Instance Attribute Details

#botsArray<Hash>

Returns List of bots currently on the server.

Returns:

  • (Array<Hash>)

    List of bots currently on the server.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#connectString

Returns Connection string (IP:port) for the server.

Returns:

  • (String)

    Connection string (IP:port) for the server.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#mapString

Returns Current map.

Returns:

  • (String)

    Current map.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#max_playersInteger

Returns Maximum number of players allowed on the server.

Returns:

  • (Integer)

    Maximum number of players allowed on the server.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#nameString

Returns Server name.

Returns:

  • (String)

    Server name.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#num_playersInteger

Returns Number of players currently on the server.

Returns:

  • (Integer)

    Number of players currently on the server.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#passwordBoolean

Returns Whether the server is password protected.

Returns:

  • (Boolean)

    Whether the server is password protected.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#pingInteger

Returns Ping time to the server in milliseconds.

Returns:

  • (Integer)

    Ping time to the server in milliseconds.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#playersArray<Hash>

Returns List of players currently on the server.

Returns:

  • (Array<Hash>)

    List of players currently on the server.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#query_portInteger

Returns Query port used to query the server.

Returns:

  • (Integer)

    Query port used to query the server.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#rawHash{String=>Object}

Returns Raw response data from the server.

Returns:

  • (Hash{String=>Object})

    Raw response data from the server.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

#versionString

Returns Server version string.

Returns:

  • (String)

    Server version string.



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/game_dig/query_result.rb', line 29

class QueryResult
  attr_accessor :name, :map, :password, :num_players, :max_players, :players, :bots,
                :connect, :ping, :query_port, :version, :raw

  def initialize(hash)
    @name        = hash['name']
    @map         = hash['map']
    @password    = hash['password']
    @num_players = hash['num_players']
    @max_players = hash['max_players']
    @players     = hash['players'] || []
    @bots        = hash['bots'] || []
    @connect     = hash['connect']
    @ping        = hash['ping']
    @query_port  = hash['query_port']
    @version     = hash['version']
    @raw         = hash['raw'] || {}
  end

  # Convenience: turn back into plain Hash.
  # @return [Hash{String=>Object}]
  def to_h
    {
      'name' => @name,
      'map' => @map,
      'password' => @password,
      'num_players' => @num_players,
      'max_players' => @max_players,
      'players' => @players,
      'bots' => @bots,
      'connect' => @connect,
      'ping' => @ping,
      'query_port' => @query_port,
      'version' => @version,
      'raw' => @raw
    }
  end

  def to_json
    to_h.to_json
  end
end

Instance Method Details

#to_hHash{String=>Object}

Convenience: turn back into plain Hash.

Returns:

  • (Hash{String=>Object})


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/game_dig/query_result.rb', line 50

def to_h
  {
    'name' => @name,
    'map' => @map,
    'password' => @password,
    'num_players' => @num_players,
    'max_players' => @max_players,
    'players' => @players,
    'bots' => @bots,
    'connect' => @connect,
    'ping' => @ping,
    'query_port' => @query_port,
    'version' => @version,
    'raw' => @raw
  }
end

#to_jsonObject



67
68
69
# File 'lib/game_dig/query_result.rb', line 67

def to_json
  to_h.to_json
end