Class: CSstats::Handler
- Inherits:
-
Object
- Object
- CSstats::Handler
- Defined in:
- lib/csstats/handler.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#max_players ⇒ Object
readonly
Returns the value of attribute max_players.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Handler
constructor
Public: Initialize file.
-
#player(id) ⇒ Object
Public: Get the player information of specified id.
- #players ⇒ Object
-
#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.
12 13 14 15 16 17 |
# File 'lib/csstats/handler.rb', line 12 def initialize( = {}) @file_path = [:path] @max_players = [:maxplayers] || 0 raise CSstats::FileNotExist unless File.exist?(file_path.to_s) end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
3 4 5 |
# File 'lib/csstats/handler.rb', line 3 def file_path @file_path end |
#max_players ⇒ Object (readonly)
Returns the value of attribute max_players.
3 4 5 |
# File 'lib/csstats/handler.rb', line 3 def max_players @max_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.
24 25 26 |
# File 'lib/csstats/handler.rb', line 24 def player(id) players[id - 1] end |
#players ⇒ Object
44 45 46 47 48 |
# File 'lib/csstats/handler.rb', line 44 def players @players ||= CSstats::Parser::Players.new( file_path, max_players: max_players ).parse end |
#players_count ⇒ Object
Public: Get total players count.
Returns the Integer of player count.
31 32 33 |
# File 'lib/csstats/handler.rb', line 31 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.
40 41 42 |
# File 'lib/csstats/handler.rb', line 40 def search_by_name(name) players.find { |player| player.nick == name } end |