Class: NeptuneApex::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/neptune_apex/status.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStatus

Returns a new instance of Status.



15
16
17
18
# File 'lib/neptune_apex/status.rb', line 15

def initialize
  @probes = {}
  @outlets = {}
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



6
7
8
# File 'lib/neptune_apex/status.rb', line 6

def date
  @date
end

#outletsObject

Returns the value of attribute outlets.



6
7
8
# File 'lib/neptune_apex/status.rb', line 6

def outlets
  @outlets
end

#powerObject

Returns the value of attribute power.



6
7
8
# File 'lib/neptune_apex/status.rb', line 6

def power
  @power
end

#probesObject

Returns the value of attribute probes.



6
7
8
# File 'lib/neptune_apex/status.rb', line 6

def probes
  @probes
end

Class Method Details

.from_xml(data) ⇒ Object



8
9
10
11
12
# File 'lib/neptune_apex/status.rb', line 8

def self.from_xml(data)
  status = Status.new
  status.read_xml(data)
  return status
end

Instance Method Details

#add_outlet(name, id, state, device_id) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/neptune_apex/status.rb', line 51

def add_outlet(name, id, state, device_id)
  @outlets[name] = {
    :id     => id,
    :state    => state,
    :device_id  => device_id,
  }
end

#add_probe(name, value, type) ⇒ Object



46
47
48
# File 'lib/neptune_apex/status.rb', line 46

def add_probe(name, value, type)
  @probes[name] = { :value => BigDecimal.new(value), :type => type }
end

#read_xml(xml) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/neptune_apex/status.rb', line 21

def read_xml(xml)
  doc = Nokogiri::XML(xml)

  @date = Date.strptime(doc.at_xpath('//status/date').text, '%m/%d/%Y %H:%M:%s')

  doc.xpath('//status/probes/probe').each{|probe|
    add_probe(
      probe.at_xpath('./name').text,
      probe.at_xpath('./value').text,
      probe.at_xpath('./type').text
    )
  }


  doc.xpath('//status/outlets/outlet').each{|outlet|
    add_outlet(
      outlet.at_xpath('./name').text,
      outlet.at_xpath('./outputID').text,
      outlet.at_xpath('./state').text,
      outlet.at_xpath('./deviceID').text
    )
  }
end