Class: RSMP::Query

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

Overview

Class that matches a single status or command item

Direct Known Subclasses

AlarmQuery, CommandQuery, StatusQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#gotObject (readonly)

Returns the value of attribute got.



5
6
7
# File 'lib/rsmp/collect/query.rb', line 5

def got
  @got
end

#messageObject (readonly)

Returns the value of attribute message.



5
6
7
# File 'lib/rsmp/collect/query.rb', line 5

def message
  @message
end

#wantObject (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?

Returns:

  • (Boolean)


14
15
16
# File 'lib/rsmp/collect/query.rb', line 14

def done?
  @got != nil
end

#forgetObject



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 message, item
  @message = message
  @got = item
end

#match?(item) ⇒ Boolean

Returns:

  • (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, message, 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