Class: Punchblock::RayoNode
- Inherits:
-
Niceogiri::XML::Node
- Object
- Niceogiri::XML::Node
- Punchblock::RayoNode
- Defined in:
- lib/punchblock/rayo_node.rb
Direct Known Subclasses
CommandNode, Component::Input::Grammar, Event, Event::Complete::Reason, Header, MediaNode, Ref
Constant Summary collapse
- @@registrations =
{}
Instance Attribute Summary collapse
-
#call_id ⇒ Object
Returns the value of attribute call_id.
-
#client ⇒ Object
Returns the value of attribute client.
-
#component_id ⇒ Object
Returns the value of attribute component_id.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#original_component ⇒ Object
Returns the value of attribute original_component.
Class Method Summary collapse
-
.class_from_registration(name, ns = nil) ⇒ Class?
Find the class to use given the name and namespace of a stanza.
-
.import(node, call_id = nil, component_id = nil) ⇒ Object
Import an XML::Node to the appropriate class.
-
.new(name = registered_name, doc = nil) ⇒ Object
Create a new Node object.
-
.register(name, ns = nil) ⇒ Object
Register a new stanza class to a name and/or namespace.
Instance Method Summary collapse
- #eql?(o, *fields) ⇒ Boolean
- #inspect ⇒ Object (also: #to_s)
-
#inspect_attributes ⇒ Object
:nodoc:.
-
#source ⇒ RayoNode
The original command issued that lead to this event.
Instance Attribute Details
#call_id ⇒ Object
Returns the value of attribute call_id.
10 11 12 |
# File 'lib/punchblock/rayo_node.rb', line 10 def call_id @call_id end |
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/punchblock/rayo_node.rb', line 10 def client @client end |
#component_id ⇒ Object
Returns the value of attribute component_id.
10 11 12 |
# File 'lib/punchblock/rayo_node.rb', line 10 def component_id @component_id end |
#connection ⇒ Object
Returns the value of attribute connection.
10 11 12 |
# File 'lib/punchblock/rayo_node.rb', line 10 def connection @connection end |
#original_component ⇒ Object
Returns the value of attribute original_component.
10 11 12 |
# File 'lib/punchblock/rayo_node.rb', line 10 def original_component @original_component end |
Class Method Details
.class_from_registration(name, ns = nil) ⇒ Class?
Find the class to use given the name and namespace of a stanza
31 32 33 |
# File 'lib/punchblock/rayo_node.rb', line 31 def self.class_from_registration(name, ns = nil) @@registrations[[name.to_s, ns]] end |
.import(node, call_id = nil, component_id = nil) ⇒ 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
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/punchblock/rayo_node.rb', line 41 def self.import(node, call_id = nil, component_id = nil) ns = (node.namespace.href if node.namespace) klass = class_from_registration(node.element_name, ns) event = if klass && klass != self klass.import node, call_id, component_id else new.inherit node end event.tap do |event| event.call_id = call_id event.component_id = component_id end end |
.new(name = registered_name, doc = nil) ⇒ Object
Create a new Node object
not provided one will be created
61 62 63 |
# File 'lib/punchblock/rayo_node.rb', line 61 def self.new(name = registered_name, doc = nil) super name, doc, registered_ns end |
.register(name, ns = nil) ⇒ 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
20 21 22 23 24 |
# File 'lib/punchblock/rayo_node.rb', line 20 def self.register(name, ns = nil) self.registered_name = name.to_s self.registered_ns = ns.is_a?(Symbol) ? RAYO_NAMESPACES[ns] : ns @@registrations[[self.registered_name, self.registered_ns]] = self end |
Instance Method Details
#eql?(o, *fields) ⇒ Boolean
73 74 75 |
# File 'lib/punchblock/rayo_node.rb', line 73 def eql?(o, *fields) super o, *(fields + inspect_attributes) end |
#inspect ⇒ Object Also known as: to_s
69 70 71 |
# File 'lib/punchblock/rayo_node.rb', line 69 def inspect "#<#{self.class} #{inspect_attributes.map { |c| "#{c}=#{self.__send__(c).inspect}" rescue nil }.compact * ', '}>" end |
#inspect_attributes ⇒ Object
:nodoc:
65 66 67 |
# File 'lib/punchblock/rayo_node.rb', line 65 def inspect_attributes # :nodoc: [:call_id, :component_id] end |
#source ⇒ RayoNode
Returns the original command issued that lead to this event.
80 81 82 83 |
# File 'lib/punchblock/rayo_node.rb', line 80 def source @source ||= client.find_component_by_id component_id if client && component_id @source ||= original_component end |