Class: TelosLWCP::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/telos_lwcp/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command:, object:, matcher:, block:) ⇒ Subscription

Returns a new instance of Subscription.



5
6
7
8
9
10
# File 'lib/telos_lwcp/subscription.rb', line 5

def initialize(command:, object:, matcher:, block:)
  self.command = Regexp === command ? command : /\A#{command}\Z/ if command
  self.object = Regexp === object ? object : /\A#{object}\Z/ if object
  self.matcher = matcher
  self.block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/telos_lwcp/subscription.rb', line 3

def block
  @block
end

#commandObject

Returns the value of attribute command.



3
4
5
# File 'lib/telos_lwcp/subscription.rb', line 3

def command
  @command
end

#matcherObject

Returns the value of attribute matcher.



3
4
5
# File 'lib/telos_lwcp/subscription.rb', line 3

def matcher
  @matcher
end

#objectObject

Returns the value of attribute object.



3
4
5
# File 'lib/telos_lwcp/subscription.rb', line 3

def object
  @object
end

Instance Method Details

#call(cmd) ⇒ Object



18
19
20
# File 'lib/telos_lwcp/subscription.rb', line 18

def call(cmd)
  block.call(cmd)
end

#match?(cmd) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/telos_lwcp/subscription.rb', line 12

def match?(cmd)
  (command.nil? || command =~ cmd.command) &&
      (object.nil? || object =~ cmd.object) &&
      (matcher.nil? || matcher.call(cmd))
end