Class: NeptuneApex::Status
- Inherits:
-
Object
- Object
- NeptuneApex::Status
- Defined in:
- lib/neptune_apex/status.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#outlets ⇒ Object
Returns the value of attribute outlets.
-
#power ⇒ Object
Returns the value of attribute power.
-
#probes ⇒ Object
Returns the value of attribute probes.
Class Method Summary collapse
Instance Method Summary collapse
- #add_outlet(name, id, state, device_id) ⇒ Object
- #add_probe(name, value, type) ⇒ Object
-
#initialize ⇒ Status
constructor
A new instance of Status.
- #read_xml(xml) ⇒ Object
Constructor Details
#initialize ⇒ Status
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
#date ⇒ Object
Returns the value of attribute date.
6 7 8 |
# File 'lib/neptune_apex/status.rb', line 6 def date @date end |
#outlets ⇒ Object
Returns the value of attribute outlets.
6 7 8 |
# File 'lib/neptune_apex/status.rb', line 6 def outlets @outlets end |
#power ⇒ Object
Returns the value of attribute power.
6 7 8 |
# File 'lib/neptune_apex/status.rb', line 6 def power @power end |
#probes ⇒ Object
Returns the value of attribute probes.
6 7 8 |
# File 'lib/neptune_apex/status.rb', line 6 def probes @probes end |
Class Method Details
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 |