Module: RubySpeech::GenericElement::ClassMethods
- Defined in:
- lib/ruby_speech/generic_element.rb
Constant Summary collapse
- @@registrations =
{}
Instance Method Summary collapse
-
#class_from_registration(name) ⇒ Class?
Find the class to use given the name and namespace of a stanza.
-
#import(node) ⇒ Object
Import an XML::Node to the appropriate class.
-
#register(name) ⇒ Object
Register a new stanza class to a name and/or namespace.
Instance Method Details
#class_from_registration(name) ⇒ Class?
Find the class to use given the name and namespace of a stanza
33 34 35 |
# File 'lib/ruby_speech/generic_element.rb', line 33 def class_from_registration(name) @@registrations[[name.to_s, namespace]] end |
#import(node) ⇒ Object
Import an XML::Node to the appropriate class
Looks up the class the node should be then creates it based on the elements of the XML::Node
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ruby_speech/generic_element.rb', line 43 def import(node) node = Nokogiri::XML.parse(node, nil, nil, Nokogiri::XML::ParseOptions::NOBLANKS).root unless node.is_a?(Nokogiri::XML::Node) || node.is_a?(GenericElement) return node.content if node.is_a?(Nokogiri::XML::Text) klass = class_from_registration node.node_name if klass && klass != self klass.import node else new(node.document).inherit node end end |
#register(name) ⇒ Object
Register a new stanza class to a name and/or namespace
This registers a namespace that is used when looking up the class name of the object to instantiate when a new stanza is received
22 23 24 25 26 |
# File 'lib/ruby_speech/generic_element.rb', line 22 def register(name) self.registered_name = name.to_s self.registered_ns = namespace @@registrations[[self.registered_name, self.registered_ns]] = self end |