Class: OBIX::Alarms
- Inherits:
-
Object
- Object
- OBIX::Alarms
- Defined in:
- lib/obix/alarms.rb
Instance Method Summary collapse
-
#count ⇒ Object
The number of alarms.
-
#initialize(source) ⇒ Alarms
constructor
Initialize an alarm service.
-
#query(options) ⇒ Object
Query alarms.
- #to_s ⇒ Object
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
#count ⇒ Object
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 from = .fetch :start to = .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_s ⇒ Object
42 43 44 |
# File 'lib/obix/alarms.rb', line 42 def to_s @alarms.to_s end |