Class: EmuPower::Notifications

Inherits:
Object
  • Object
show all
Defined in:
lib/emu_power/notifications.rb

Defined Under Namespace

Classes: BlockPriceDetail, ConnectionStatus, CurrentPeriodUsage, CurrentSummationDelivered, DeviceInfo, FastPollStatus, InstantaneousDemand, LastPeriodUsage, MessageCluster, MeterInfo, MeterList, NetworkInfo, Notification, PriceCluster, ScheduleInfo, TimeCluster

Class Method Summary collapse

Class Method Details

.construct(xml) ⇒ Object

Dispatch to the appropriate container class based on the type. Expects a data hash. Returns nil on bad message.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/emu_power/notifications.rb', line 91

def self.construct(xml)

	hash = Nori.new.parse(xml)

	# Extract the root of the hash and dispatch to the appropriate
	# container class.
	type, data = hash.first

	return nil unless notify_roots.include?(type)

	klass = self.const_get(type)
	return klass.new(data)

end

.notify_rootsObject

Helper to get the element names of all types



107
108
109
# File 'lib/emu_power/notifications.rb', line 107

def self.notify_roots
	return Notification.subclasses.map(&:root_name)
end