Class: OBIX::History

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

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ History

Initialize a history.

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



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

def initialize source
  @history = OBIX.parse source
end

Instance Method Details

#countObject

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

#endObject

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 options
  from = options.fetch :start
  to   = options.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

#startObject

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

#timezoneObject

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_sObject



59
60
61
# File 'lib/obix/history.rb', line 59

def to_s
  @history.to_s
end