Class: TelosLWCP::Subscription
- Inherits:
-
Object
- Object
- TelosLWCP::Subscription
- Defined in:
- lib/telos_lwcp/subscription.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#command ⇒ Object
Returns the value of attribute command.
-
#matcher ⇒ Object
Returns the value of attribute matcher.
-
#object ⇒ Object
Returns the value of attribute object.
Instance Method Summary collapse
- #call(cmd) ⇒ Object
-
#initialize(command:, object:, matcher:, block:) ⇒ Subscription
constructor
A new instance of Subscription.
- #match?(cmd) ⇒ Boolean
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
#block ⇒ Object
Returns the value of attribute block.
3 4 5 |
# File 'lib/telos_lwcp/subscription.rb', line 3 def block @block end |
#command ⇒ Object
Returns the value of attribute command.
3 4 5 |
# File 'lib/telos_lwcp/subscription.rb', line 3 def command @command end |
#matcher ⇒ Object
Returns the value of attribute matcher.
3 4 5 |
# File 'lib/telos_lwcp/subscription.rb', line 3 def matcher @matcher end |
#object ⇒ Object
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
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 |