Class: CSstats::Handler
- Inherits:
-
Object
- Object
- CSstats::Handler
- Defined in:
- lib/csstats/handler.rb
Instance Attribute Summary collapse
-
#maxplayers ⇒ Object
readonly
Returns the value of attribute maxplayers.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Handler
constructor
Public: Initialize file.
-
#player(id) ⇒ Object
Public: Get the player information of specified id.
-
#players_count ⇒ Object
Public: Get total players count.
-
#search_by_name(name) ⇒ Object
Public: Get player by specified name.
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( = {}) @path = [:path] @maxplayers = [: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
#maxplayers ⇒ Object (readonly)
Returns the value of attribute maxplayers.
5 6 7 |
# File 'lib/csstats/handler.rb', line 5 def maxplayers @maxplayers end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/csstats/handler.rb', line 5 def path @path end |
#players ⇒ Object (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_count ⇒ Object
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 |