Class: Australium::Game

Inherits:
Object
  • Object
show all
Includes:
EventFilters
Defined in:
lib/australium/game.rb

Overview

Represents a full game of TF2, comprised of individual Events.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EventFilters

#chat_messages, #connects, #disconnects, #entrances, #kills, #map_loads, #map_starts, #name_changes, #role_changes, #suicides, #team_joins, #triggers

Constructor Details

#initialize(events) ⇒ Game

Returns a new instance of Game

Parameters:

  • events (Array<Events>)

    events that took place during the game


19
20
21
# File 'lib/australium/game.rb', line 19

def initialize(events)
  @events = events
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events


16
17
18
# File 'lib/australium/game.rb', line 16

def events
  @events
end

Instance Method Details

#inspectString

Hide instance variables from #inspect to prevent clutter on interactive terminals.

Returns:

  • (String)

41
# File 'lib/australium/game.rb', line 41

def inspect ; self.to_s end

#map_nameString

Returns the name of the map that was played.

Returns:

  • (String)

    map name


35
36
37
# File 'lib/australium/game.rb', line 35

def map_name
  @events.select { |e| e.is_a?(MapStart) }.last.map_name
end

#playersArray<Player>

Returns an array of all Players who connected to the server during this game. Caches the return value after the first call.

Returns:

  • (Array<Player>)

    players who participated in the game


26
27
28
29
30
31
# File 'lib/australium/game.rb', line 26

def players
  @players ||= @events.reverse.each_with_object([]) do |event, all_players|
    break all_players if event.state.nil? || event.state.players.nil?
    all_players.concat event.state.players.reject { |p| all_players.include?(p) }
  end
end