Class: Australium::Event

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/australium/event.rb

Overview

Represents a generic Event that occurs during a Game.

Constant Summary collapse

TIMESTAMP_REGEX =
%r(L [0-9]{2}/[0-9]{2}/[0-9]{4} - [0-9]{2}:[0-9]{2}:[0-9]{2})
PROPERTY_REGEX =
/\(([^ ]+) "([^"]+)"\)/

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Event

Returns a new instance of Event.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/australium/event.rb', line 21

def initialize(data)
  super(data)

  # Replace anything matching a Player string with a Player object.
  self.each_pair do |key, value|
    if value =~ Player::LOG_REGEX && key != :raw
      player_data = Player::LOG_REGEX.match(value).to_h
      self[key] = Player.new(player_data)
    end
  end

  # If we're being stateful, make sure referenced Players are included in the GameState
  unless self.state.nil?
    self.to_h.select { |_, v| v.is_a?(Player) }.each_pair do |key, value|
      if self.state.players.include?(value)
        self[key] = self.state.players.find { |p| p == value }
      else
        self.state.players << value
      end
    end
  end
end

Class Attribute Details

.event_classesObject

Returns the value of attribute event_classes.



14
15
16
# File 'lib/australium/event.rb', line 14

def event_classes
  @event_classes
end

Instance Attribute Details

#rawString

Returns the raw log message.

Returns:

  • (String)

    the raw log message.



10
# File 'lib/australium/event.rb', line 10

TIMESTAMP_REGEX = %r(L [0-9]{2}/[0-9]{2}/[0-9]{4} - [0-9]{2}:[0-9]{2}:[0-9]{2})

Class Method Details

.inherited(by) ⇒ Object



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

def inherited(by)
  @event_classes ||= []
  @event_classes << by
end

Instance Method Details

#to_sObject



44
# File 'lib/australium/event.rb', line 44

def to_s ; raw end