Class: AgentXmpp::Xmpp::Element
- Inherits:
-
REXML::Element
- Object
- REXML::Element
- AgentXmpp::Xmpp::Element
- Defined in:
- lib/agent_xmpp/xmpp/element.rb
Overview
Direct Known Subclasses
DiscoFeature, DiscoIdentity, DiscoItem, Entry, ErrorResponse, Event, IqCommand, IqPubSub, IqPubSubOwner, IqPublish, IqQuery, Item, Items, RosterItem, Stanza, Subscription, Subscriptions, X, XDataField, XDataInstructions, XDataItem, XDataReported, XDataTitle
Constant Summary collapse
- @@name_xmlns_classes =
.….….….….….….….….….….….….….….….….….….….….….….….….……
{}
Class Method Summary collapse
-
.class_for_name_xmlns(name, xmlns) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
.import(element) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
.name_xmlns(name, xmlns = nil) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
.name_xmlns_for_class(klass) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
.xmpp_attribute(*args) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….
-
.xmpp_child(*args) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
Instance Method Summary collapse
-
#<<(child) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….
-
#clone ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#initialize(*arg) ⇒ Element
constructor
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#parent=(new_parent) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#set_xml_lang(l) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#typed_add(element) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#xml_lang ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
-
#xml_lang=(l) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
Methods inherited from REXML::Element
#delete_elements, #first_element, #first_element_text, #import, #replace_element_text
Constructor Details
#initialize(*arg) ⇒ Element
.….….….….….….….….….….….….….….….….….….….….….….….….……
90 91 92 93 94 95 96 97 98 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 90 def initialize(*arg) if arg.empty? name, xmlns = self.class::name_xmlns_for_class(self.class) super(name) add_namespace(xmlns) else super end end |
Class Method Details
.class_for_name_xmlns(name, xmlns) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
35 36 37 38 39 40 41 42 43 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 35 def class_for_name_xmlns(name, xmlns) if @@name_xmlns_classes.has_key? [name, xmlns] @@name_xmlns_classes[[name, xmlns]] elsif @@name_xmlns_classes.has_key? [name, nil] @@name_xmlns_classes[[name, nil]] else REXML::Element end end |
.import(element) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
46 47 48 49 50 51 52 53 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 46 def import(element) klass = class_for_name_xmlns(element.name, element.namespace) if klass != self and klass.ancestors.include?(self) klass.new.import(element) else self.new.import(element) end end |
.name_xmlns(name, xmlns = nil) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
18 19 20 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 18 def name_xmlns(name, xmlns=nil) @@name_xmlns_classes[[name, xmlns]] = self end |
.name_xmlns_for_class(klass) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 23 def name_xmlns_for_class(klass) klass.ancestors.each do |klass1| @@name_xmlns_classes.each do |name_xmlns,k| if klass1 == k return name_xmlns end end end raise NoNameXmlnsRegistered.new(klass) end |
.xmpp_attribute(*args) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 56 def xmpp_attribute(*args) sym = (args.pop[:sym] if args.last.kind_of?(Hash)).nil? ? '' : '.to_sym' args.each do |a| class_eval <<-DEF def #{a.to_s} attr = attributes['#{a.to_s}'] attr.nil? ? nil : attr#{sym} end def #{a.to_s}=(v) attributes['#{a.to_s}'] = v.to_s end DEF end end |
.xmpp_child(*args) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 72 def xmpp_child(*args) args.each do |a| class_eval <<-DEF def #{a.to_s} first_element('#{a.to_s}') end def #{a.to_s}=(v) delete_elements(v.name) add(v) end DEF end end |
Instance Method Details
#<<(child) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….….
147 148 149 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 147 def <<(child) add(child); self end |
#clone ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
124 125 126 127 128 129 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 124 def clone cloned = self.class.new cloned.add_attributes self.attributes.clone cloned.context = @context cloned end |
#parent=(new_parent) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
113 114 115 116 117 118 119 120 121 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 113 def parent=(new_parent) if parent and parent.namespace('') == namespace('') and attributes['xmlns'].nil? add_namespace parent.namespace('') end super if new_parent and new_parent.namespace('') == namespace('') delete_namespace end end |
#set_xml_lang(l) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
142 143 144 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 142 def set_xml_lang(l) self.xml_lang = l; self end |
#typed_add(element) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 101 def typed_add(element) if element.kind_of? REXML::Element element_ns = (element.namespace.to_s == '') ? namespace : element.namespace klass = Element::class_for_name_xmlns(element.name, element_ns) if klass != element.class element = klass.import(element) end end super(element) end |
#xml_lang ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
132 133 134 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 132 def xml_lang attributes['xml:lang'] end |
#xml_lang=(l) ⇒ Object
.….….….….….….….….….….….….….….….….….….….….….….….….……
137 138 139 |
# File 'lib/agent_xmpp/xmpp/element.rb', line 137 def xml_lang=(l) attributes['xml:lang'] = l end |