Class: RSMP::Query
- Inherits:
-
Object
- Object
- RSMP::Query
- Defined in:
- lib/rsmp/collect/query.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) ⇒ Query
constructor
A new instance of Query.
- #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) ⇒ Query
Returns a new instance of Query.
7 8 9 10 11 |
# File 'lib/rsmp/collect/query.rb', line 7 def initialize want @want = want @got = nil @message = nil end |
Instance Attribute Details
#got ⇒ Object (readonly)
Returns the value of attribute got.
5 6 7 |
# File 'lib/rsmp/collect/query.rb', line 5 def got @got end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
5 6 7 |
# File 'lib/rsmp/collect/query.rb', line 5 def @message end |
#want ⇒ Object (readonly)
Returns the value of attribute want.
5 6 7 |
# File 'lib/rsmp/collect/query.rb', line 5 def want @want end |
Instance Method Details
#done? ⇒ Boolean
Are we done, i.e. did the last checked item match?
14 15 16 |
# File 'lib/rsmp/collect/query.rb', line 14 def done? @got != nil end |
#forget ⇒ Object
36 37 38 39 |
# File 'lib/rsmp/collect/query.rb', line 36 def forget @message = nil @got = nil end |
#keep(message, item) ⇒ Object
31 32 33 34 |
# File 'lib/rsmp/collect/query.rb', line 31 def keep , item @message = @got = item end |
#match?(item) ⇒ Boolean
41 42 |
# File 'lib/rsmp/collect/query.rb', line 41 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
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rsmp/collect/query.rb', line 20 def perform_match item, , block matched = match? item if matched != nil if block status = block.call(nil,item) matched = status if status == true || status == false end end matched end |