class EmuPower::Notifications

Public Class Methods

construct(xml) click to toggle source

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

# 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_roots() click to toggle source

Helper to get the element names of all types

# File lib/emu_power/notifications.rb, line 107
def self.notify_roots
        return Notification.subclasses.map(&:root_name)
end