Class: RSMP::CommandMatcher

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

Overview

Class for matching a command

Instance Attribute Summary

Attributes inherited from Matcher

#got, #message, #want

Instance Method Summary collapse

Methods inherited from Matcher

#done?, #forget, #initialize, #keep, #perform_match

Constructor Details

This class inherits a constructor from RSMP::Matcher

Instance Method Details

#match?(item) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/rsmp/collect/command_matcher.rb', line 22

def match?(item)
  code_match = match_code?(item)
  return code_match if code_match.nil?

  match_value?(item)
end

#match_code?(item) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
# File 'lib/rsmp/collect/command_matcher.rb', line 4

def match_code?(item)
  return nil if @want['cCI'] && @want['cCI'] != item['cCI']
  return nil if @want['n'] && @want['n'] != item['n']

  true
end

#match_value?(item) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
# File 'lib/rsmp/collect/command_matcher.rb', line 11

def match_value?(item)
  return true unless @want['v']

  if @want['v'].is_a? Regexp
    return false if item['v'] !~ @want['v']
  elsif item['v'] != @want['v']
    return false
  end
  true
end