Class: Australium::Event

Inherits:
OpenStruct 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 =
/\(([^ ]+) "([^"]+)"\)/
TIMESTAMP_FORMAT =
'L %m/%d/%Y - %H:%M:%S'

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OpenStruct

#initialize_clone

Constructor Details

#initialize(data) ⇒ Event

Returns a new instance of Event


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

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


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

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


17
18
19
20
# File 'lib/australium/event.rb', line 17

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

Instance Method Details

#to_sObject


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

def to_s ; raw end