Class: RSMP::Matcher

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

Overview

Class that matches a single status or command item

Direct Known Subclasses

AlarmMatcher, CommandMatcher, StatusMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(want) ⇒ Matcher

Returns a new instance of Matcher.



6
7
8
9
10
# File 'lib/rsmp/collect/matcher.rb', line 6

def initialize(want)
  @want = want
  @got = nil
  @message = nil
end

Instance Attribute Details

#gotObject (readonly)

Returns the value of attribute got.



4
5
6
# File 'lib/rsmp/collect/matcher.rb', line 4

def got
  @got
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/rsmp/collect/matcher.rb', line 4

def message
  @message
end

#wantObject (readonly)

Returns the value of attribute want.



4
5
6
# File 'lib/rsmp/collect/matcher.rb', line 4

def want
  @want
end

Instance Method Details

#done?Boolean

Are we done, i.e. did the last checked item match?

Returns:

  • (Boolean)


13
14
15
# File 'lib/rsmp/collect/matcher.rb', line 13

def done?
  @got != nil
end

#forgetObject



33
34
35
36
# File 'lib/rsmp/collect/matcher.rb', line 33

def forget
  @message = nil
  @got = nil
end

#keep(message, item) ⇒ Object



28
29
30
31
# File 'lib/rsmp/collect/matcher.rb', line 28

def keep(message, item)
  @message = message
  @got = item
end

#match?(item) ⇒ Boolean

Returns:

  • (Boolean)


38
# File 'lib/rsmp/collect/matcher.rb', line 38

def match?(item); end

#perform_match(item, _message, block) ⇒ Object

Check an item and set @done to true if it matches Store the item and corresponding message if there’s a positive or negative match



19
20
21
22
23
24
25
26
# File 'lib/rsmp/collect/matcher.rb', line 19

def perform_match(item, _message, block)
  matched = match? item
  if !matched.nil? && block
    status = block.call(nil, item)
    matched = status if [true, false].include?(status)
  end
  matched
end