Class: RSMP::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/rsmp/collect/filter.rb

Overview

Filter messages based on type, direction and component id. Used by Collectors.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ingoing: true, outgoing: true, type: nil, component: nil) ⇒ Filter

Returns a new instance of Filter.



7
8
9
10
11
12
# File 'lib/rsmp/collect/filter.rb', line 7

def initialize(ingoing: true, outgoing: true, type: nil, component: nil)
  @ingoing = ingoing
  @outgoing = outgoing
  @type = type ? [type].flatten : nil
  @component = component
end

Instance Attribute Details

#componentObject (readonly)

Returns the value of attribute component.



5
6
7
# File 'lib/rsmp/collect/filter.rb', line 5

def component
  @component
end

#ingoingObject (readonly)

Returns the value of attribute ingoing.



5
6
7
# File 'lib/rsmp/collect/filter.rb', line 5

def ingoing
  @ingoing
end

#outgoingObject (readonly)

Returns the value of attribute outgoing.



5
6
7
# File 'lib/rsmp/collect/filter.rb', line 5

def outgoing
  @outgoing
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/rsmp/collect/filter.rb', line 5

def type
  @type
end

Instance Method Details

#accept?(message) ⇒ Boolean

Check a message against our match criteria

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/rsmp/collect/filter.rb', line 15

def accept?(message)
  return false unless direction_matches?(message)
  return false unless type_matches?(message)
  return false unless component_matches?(message)

  true
end

#reject?(message) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/rsmp/collect/filter.rb', line 48

def reject?(message)
  !accept?(message)
end