Class: RSMP::AlarmCollector

Inherits:
Collector show all
Defined in:
lib/rsmp/collect/alarm_collector.rb

Overview

Class for waiting for specific command responses

Instance Attribute Summary

Attributes inherited from Collector

#condition, #error, #messages, #status, #task

Instance Method Summary collapse

Methods inherited from Collector

#cancel, #cancelled?, #collect, #collect!, #collecting?, #complete, #describe, #describe_progress, #do_stop, #done?, #ingoing?, #inspect, #keep, #notify, #notify_disconnect, #notify_error, #notify_schema_error, #ok!, #ok?, #outgoing?, #perform_match, #ready?, #reject_not_ack, #reset, #start, #timeout?, #use_task, #wait, #wait!

Methods inherited from Listener

#change_notifier, #notify, #notify_error

Methods included from Inspect

#inspect, #inspector

Constructor Details

#initialize(proxy, options = {}) ⇒ AlarmCollector

Returns a new instance of AlarmCollector.



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

def initialize proxy,options={}
  @query = options[:query] || {}
  super proxy, options.merge(
    type: 'Alarm',
    title:'alarm'
  )
end

Instance Method Details

#type_match?(message) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rsmp/collect/alarm_collector.rb', line 12

def type_match? message
  return false if super(message) == false

  # match fixed attributes
  %w{aCId aSp ack aS sS cat pri}.each do |key|
    want = @query[key]
    got = message.attribute(key)
    case want
    when Regexp
      return false if got !~ want
    when String
      return false if got != want
    end
  end

  # match rvs items
  if @query['rvs']
    query_rvs = @query['rvs']
    message_rvs = message.attributes['rvs']
    return false unless message_rvs
    return false unless query_rvs.all? do |query_item|
      return false unless message_rvs.any? do |message_item|
        next message_item['n'] == query_item['n'] && message_item['v'] == query_item['v']
      end
      next true
    end
  end
  true
end