Class: CSstats::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/csstats/handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Handler

Public: Initialize file.

options - The Hash options:

:path       - The String of csstats.dat file path (required).
:maxplayers - The Integer of how many players to return (optional).

Returns nothing.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/csstats/handler.rb', line 14

def initialize(options = {})
  @path = options[:path]
  @maxplayers = options[:maxplayers] || 0

  @players = []
  raise CSstats::FileNotExist unless File.exist?(path.to_s)

  @file = File.new(path, 'r')
  _file_version = read_short_data(@file)

  read_players!
end

Instance Attribute Details

#maxplayersObject (readonly)

Returns the value of attribute maxplayers.



5
6
7
# File 'lib/csstats/handler.rb', line 5

def maxplayers
  @maxplayers
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/csstats/handler.rb', line 5

def path
  @path
end

#playersObject (readonly)

Returns the value of attribute players.



5
6
7
# File 'lib/csstats/handler.rb', line 5

def players
  @players
end

Instance Method Details

#player(id) ⇒ Object

Public: Get the player information of specified id.

id - The Integer of player id.

Returns the Mash of player information.



32
33
34
# File 'lib/csstats/handler.rb', line 32

def player(id)
  players[id - 1]
end

#players_countObject

Public: Get total players count.

Returns the Integer of player count.



39
40
41
# File 'lib/csstats/handler.rb', line 39

def players_count
  players.count
end

#search_by_name(name) ⇒ Object

Public: Get player by specified name.

name - The String of player name.

Returns the Mash of player information.



48
49
50
# File 'lib/csstats/handler.rb', line 48

def search_by_name(name)
  players.find { |player| player.nick == name }
end