Class: OBIX::History
- Inherits:
-
Object
- Object
- OBIX::History
- Defined in:
- lib/obix/history.rb
Instance Method Summary collapse
-
#count ⇒ Object
The number of history records contained by the history.
-
#end ⇒ Object
The timestamp of the newest record contained by the history.
-
#initialize(source) ⇒ History
constructor
Initialize a history.
-
#query(options) ⇒ Object
Query the history records contained by the history.
-
#start ⇒ Object
The timestamp of the oldest record contained by the history.
-
#timezone ⇒ Object
The timezone of the history data.
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#count ⇒ Object
The number of history records contained by the history.
Returns an Integer.
15 16 17 |
# File 'lib/obix/history.rb', line 15 def count @history.objects.find { |o| o.name == "count" }.val end |
#end ⇒ Object
The timestamp of the newest record contained by the history.
27 28 29 |
# File 'lib/obix/history.rb', line 27 def end @history.objects.find { |o| o.name == "end" }.val end |
#query(options) ⇒ Object
Query the history records contained by the history.
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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/obix/history.rb', line 41 def query from = .fetch :start to = .fetch :end query = @history.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 history = query.invoke filter history.objects.find { |o| o.name == "data" } end |
#start ⇒ Object
The timestamp of the oldest record contained by the history.
Returns a DateTime instance.
22 23 24 |
# File 'lib/obix/history.rb', line 22 def start @history.objects.find { |o| o.name == "start" }.val end |
#timezone ⇒ Object
The timezone of the history data.
32 33 34 |
# File 'lib/obix/history.rb', line 32 def timezone @history.objects.find { |o| o.name == "tz" }.val end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/obix/history.rb', line 59 def to_s @history.to_s end |