Class: Rubycord::Events::PlayingEventHandler

Inherits:
EventHandler show all
Defined in:
lib/rubycord/events/presence.rb

Overview

Event handler for PlayingEvent

Instance Method Summary collapse

Methods inherited from EventHandler

#after_call, #call, #initialize, #match, #matches_all

Constructor Details

This class inherits a constructor from Rubycord::Events::EventHandler

Instance Method Details

#matches?(event) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/rubycord/events/presence.rb', line 100

def matches?(event)
  # Check for the proper event type
  return false unless event.is_a? PlayingEvent

  [
    matches_all(@attributes[:from], event.user) do |a, e|
      a == case a
      when String
        e.name
      when Integer
        e.id
      else
        e
      end
    end,
    matches_all(@attributes[:game], event.game) do |a, e|
      a == e
    end,
    matches_all(@attributes[:type], event.type) do |a, e|
      a == e
    end,
    matches_all(@attributes[:client_status], event.client_status) do |a, e|
      e.slice(a.keys) == a
    end
  ].reduce(true, &:&)
end