Class: Adhearsion::Rayo::RayoNode
- Defined in:
- lib/adhearsion/rayo/rayo_node.rb
Direct Known Subclasses
Event, CommandNode, Component::Input::Grammar, Component::Output::Document, Component::ReceiveFax::Fax, Component::SendFax::FaxDocument, Ref
Constant Summary collapse
- @@registrations =
{}
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#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.
-
.from_xml(node, call_id = nil, component_id = nil, uri = nil, timestamp = nil) ⇒ Object
Import an XML::Node to the appropriate class.
-
.register(name, ns = nil) ⇒ Object
Register a new stanza class to a name and/or namespace.
Instance Method Summary collapse
- #==(o) ⇒ Object
- #inherit(xml_node) ⇒ Object
- #inspect ⇒ Object (also: #to_s)
- #rayo_attributes ⇒ Object
- #rayo_children(root) ⇒ Object
-
#source ⇒ RayoNode
The original command issued that lead to this event.
- #to_rayo(parent = nil) ⇒ Object
- #to_xml ⇒ Object
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
25 26 27 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 25 def client @client end |
#connection ⇒ Object
Returns the value of attribute connection.
25 26 27 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 25 def connection @connection end |
#original_component ⇒ Object
Returns the value of attribute original_component.
25 26 27 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 25 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
46 47 48 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 46 def self.class_from_registration(name, ns = nil) @@registrations[[name.to_s, ns]] end |
.from_xml(node, call_id = nil, component_id = nil, uri = nil, timestamp = 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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 56 def self.from_xml(node, call_id = nil, component_id = nil, uri = nil, = nil) ns = (node.namespace.href if node.namespace) klass = class_from_registration(node.name, ns) if klass && klass != self klass.from_xml node, call_id, component_id else new.inherit node end.tap do |event| event.target_call_id = call_id event.component_id = component_id event.source_uri = uri event. = if end 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
35 36 37 38 39 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 35 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
#==(o) ⇒ Object
83 84 85 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 83 def ==(o) o.is_a?(self.class) && self.comparable_attributes == o.comparable_attributes end |
#inherit(xml_node) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 71 def inherit(xml_node) xml_node.attributes.each do |key, attr_node| setter_method = "#{key.gsub('-', '_')}=" send setter_method, xml_node[key] if respond_to?(setter_method) end self end |
#inspect ⇒ Object Also known as: to_s
79 80 81 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 79 def inspect "#<#{self.class} #{to_hash.map { |k, v| "#{k}=#{v.inspect}" }.compact * ', '}>" end |
#rayo_attributes ⇒ Object
95 96 97 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 95 def rayo_attributes {} end |
#rayo_children(root) ⇒ Object
99 100 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 99 def rayo_children(root) end |
#source ⇒ RayoNode
Returns the original command issued that lead to this event.
90 91 92 93 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 90 def source @source ||= client.find_component_by_uri source_uri if client && source_uri @source ||= original_component end |
#to_rayo(parent = nil) ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 102 def to_rayo(parent = nil) parent = parent.parent if parent.is_a?(Nokogiri::XML::Builder) Nokogiri::XML::Builder.with(parent) do |xml| xml.send(registered_name, {xmlns: registered_ns}.merge(rayo_attributes.delete_if { |k,v| v.nil? })) do |root| rayo_children root end end.doc.root end |
#to_xml ⇒ Object
112 113 114 |
# File 'lib/adhearsion/rayo/rayo_node.rb', line 112 def to_xml to_rayo.to_xml end |