Class: MatrixSdk::MatrixEvent

Inherits:
Event show all
Defined in:
lib/matrix_sdk/util/events.rb

Instance Attribute Summary collapse

Attributes inherited from Event

#handled

Instance Method Summary collapse

Methods inherited from Event

#handled?

Methods included from Extensions

#events, #ignore_inspect

Constructor Details

#initialize(sender, event = nil, filter = nil) ⇒ MatrixEvent

Returns a new instance of MatrixEvent.



74
75
76
77
78
# File 'lib/matrix_sdk/util/events.rb', line 74

def initialize(sender, event = nil, filter = nil)
  @event = event
  @filter = filter || @event[:type]
  super sender
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



99
100
101
102
103
# File 'lib/matrix_sdk/util/events.rb', line 99

def method_missing(method, *args)
  return event[method] if event.key? method

  super
end

Instance Attribute Details

#eventObject Also known as: data

Returns the value of attribute event.



69
70
71
# File 'lib/matrix_sdk/util/events.rb', line 69

def event
  @event
end

#filterObject

Returns the value of attribute filter.



69
70
71
# File 'lib/matrix_sdk/util/events.rb', line 69

def filter
  @filter
end

Instance Method Details

#[](key) ⇒ Object



91
92
93
# File 'lib/matrix_sdk/util/events.rb', line 91

def [](key)
  event[key]
end

#matches?(filter, filter_override = nil) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
# File 'lib/matrix_sdk/util/events.rb', line 80

def matches?(filter, filter_override = nil)
  return true if filter_override.nil? && (@filter.nil? || filter.nil?)

  to_match = filter_override || @filter
  if filter.is_a? Regexp
    filter.match(to_match) { true } || false
  else
    to_match == filter
  end
end

#respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


105
106
107
108
109
# File 'lib/matrix_sdk/util/events.rb', line 105

def respond_to_missing?(method, *)
  return true if event.key? method

  super
end

#to_sObject



95
96
97
# File 'lib/matrix_sdk/util/events.rb', line 95

def to_s
  "#{event[:type]}: #{event.reject { |k, _v| k == :type }.to_json}"
end