Class: OBIX::Alarms

Inherits:
Object
  • Object
show all
Defined in:
lib/obix/alarms.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ Alarms

Initialize an alarm service.

source - A Hash of options (see OBIX#parse for details).



8
9
10
# File 'lib/obix/alarms.rb', line 8

def initialize source
  @alarms = OBIX.parse source
end

Instance Method Details

#countObject

The number of alarms.

Returns an Integer.



15
16
17
# File 'lib/obix/alarms.rb', line 15

def count
  @alarms.objects.find { |o| o.name == "count" }.val
end

#query(options) ⇒ Object

Query alarms.

options - A Hash of options:

:start - A DateTime instance describing the earliest time to query history for.
:end   - A DateTime instance describing the latest time to query history for.


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/obix/alarms.rb', line 24

def query options
  from = options.fetch :start
  to   = options.fetch :end

  query = @alarms.objects.find { |o| o.name == "query" }

  filter = OBIX::Builder.new do
    obj do
      abstime name: "start", val: from.iso8601
      abstime name: "end", val: to.iso8601
    end
  end.object

  alarms = query.invoke filter

  alarms.objects.find { |o| o.name == "data" }
end

#to_sObject



42
43
44
# File 'lib/obix/alarms.rb', line 42

def to_s
  @alarms.to_s
end