Class: Moon::Event

Inherits:
Object show all
Defined in:
lib/moon/packages/std/event.rb

Overview

Base class for every other Event.

Constant Summary collapse

@@id =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Event

Returns a new instance of Event.

Parameters:


14
15
16
17
# File 'lib/moon/packages/std/event.rb', line 14

def initialize(type)
  @type = type
  @id = @@id += 1
end

Instance Attribute Details

#idInteger

Returns id of the event.

Returns:


11
12
13
# File 'lib/moon/packages/std/event.rb', line 11

def id
  @id
end

#typeSymbol

Returns type of event.

Returns:


8
9
10
# File 'lib/moon/packages/std/event.rb', line 8

def type
  @type
end

Class Method Details

.make_filter(options) ⇒ Proc

Creates a filter proc for handling extra options from an Eventable#on

Parameters:

Returns:

  • (Proc)

23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/moon/packages/std/event.rb', line 23

def self.make_filter(options)
  lambda do |event|
    # Checks that all pairs in the options match the event's properties.
    #
    # @example KeyboardEvent with key
    #   # this will filter KeyboardEvents with the :press action and :a key.
    #   on Moon::KeyboardEvent, action: :press, key: :a do |ev|
    #     do_action ev
    #   end
    options.all? do |k, v|
      event.send(k) == v
    end
  end
end