Class: RSMP::Matcher
- Inherits:
-
Object
- Object
- RSMP::Matcher
- Defined in:
- lib/rsmp/collect/matcher.rb
Overview
Class that matches a single status or command item
Direct Known Subclasses
Instance Attribute Summary collapse
-
#got ⇒ Object
readonly
Returns the value of attribute got.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#want ⇒ Object
readonly
Returns the value of attribute want.
Instance Method Summary collapse
-
#done? ⇒ Boolean
Are we done, i.e.
- #forget ⇒ Object
-
#initialize(want) ⇒ Matcher
constructor
A new instance of Matcher.
- #keep(message, item) ⇒ Object
- #match?(item) ⇒ Boolean
-
#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.
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
#got ⇒ Object (readonly)
Returns the value of attribute got.
4 5 6 |
# File 'lib/rsmp/collect/matcher.rb', line 4 def got @got end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/rsmp/collect/matcher.rb', line 4 def @message end |
#want ⇒ Object (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?
13 14 15 |
# File 'lib/rsmp/collect/matcher.rb', line 13 def done? @got != nil end |
#forget ⇒ Object
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(, item) @message = @got = item end |
#match?(item) ⇒ 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, , block) matched = match? item if !matched.nil? && block status = block.call(nil, item) matched = status if [true, false].include?(status) end matched end |