Sha256: dd3cd50f3fc51cc4347485358eda76dd5f573a14c89cd60944de8c499948dd94

Contents?: true

Size: 710 Bytes

Versions: 2

Compression:

Stored size: 710 Bytes

Contents

class QstatRequest
  def initialize(hostname)
    @result = JSON.parse(%x[qstat -json -P -qws #{hostname}]).first
  end

  def output
    <<~HEREDOC
      **#{address} | #{map} | #{numplayers}/#{maxplayers}**
      #{player_table}
    HEREDOC
  end

  def address
    @result["address"]
  end

  def map
    @result["map"]
  end

  def numplayers
    @result["numplayers"]
  end

  def maxplayers
    @result["maxplayers"]
  end

  def player_table
    players && players.sort_by { |player| player.team.number }.map(&:to_row).join("\n")
  end

  def players
    @result["players"] && @result["players"].map do |player_data|
      Player.new(player_data)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qwtf_discord_bot-0.3.3 lib/qstat_request.rb
qwtf_discord_bot-0.3.2 lib/qstat_request.rb