Class: Alchemist::Event

Inherits:
Object show all
Defined in:
lib/alchemist-server/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_string, time) ⇒ Event

Returns a new instance of Event.



5
6
7
8
# File 'lib/alchemist-server/event.rb', line 5

def initialize(command_string, time)
  @command_string = command_string
  @time = time
end

Instance Attribute Details

#command_stringObject (readonly)

Returns the value of attribute command_string.



3
4
5
# File 'lib/alchemist-server/event.rb', line 3

def command_string
  @command_string
end

Instance Method Details

#happen(history) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/alchemist-server/event.rb', line 10

def happen(history)
  avatar_name, command, *args = @command_string.split /\s+/

  if command_mod = COMMANDS.detect { |c| match_command? command, c }
    command_mod.run avatar_name, history, *args
  else
    Outcome.new response: "error Unknown Command: #{command}"
  end
end

#to_sObject



20
21
22
23
24
25
# File 'lib/alchemist-server/event.rb', line 20

def to_s
  <<-str
#{@command_string}
#{@time}
  str
end