Class: RSMP::StatusMatcher

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

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
# File 'lib/rsmp/collect/status_matcher.rb', line 22

def match?(item)
  return nil unless match_code?(item)

  match_value?(item)
end

#match_code?(item) ⇒ Boolean

Returns:

  • (Boolean)


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

def match_code?(item)
  return false if @want['sCI'] && @want['sCI'] != item['sCI']
  return false if @want['cO'] && @want['cO'] != item['cO']
  return false 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/status_matcher.rb', line 11

def match_value?(item)
  return false if @want['q'] && @want['q'] != item['q']

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