The JID class represents a Jabber Identifier as described by RFC3920 section 3.1.
Note that you can use JIDs also for Sorting, Hash keys, …
Escape JID
# File lib/xmpp4r/jid.rb, line 152 def JID::escape(jid) return jid.to_s.gsub('@', '%') end
Create a new JID. If called as new('a@b/c'), parse the string and split (node, domain, resource)
# File lib/xmpp4r/jid.rb, line 26 def initialize(node = "", domain = nil, resource = nil) @resource = resource @domain = domain @node = node if @domain.nil? and @resource.nil? and @node @node, @domain, @resource = @node.to_s.scan(PATTERN).first end if USE_STRINGPREP @node = IDN::Stringprep.nodeprep(@node) if @node @domain = IDN::Stringprep.nameprep(@domain) if @domain @resource = IDN::Stringprep.resourceprep(@resource) if @resource else @node.downcase! if @node @domain.downcase! if @domain end raise ArgumentError, 'Node too long' if (@node || '').length > 1023 raise ArgumentError, 'Domain too long' if (@domain || '').length > 1023 raise ArgumentError, 'Resource too long' if (@resource || '').length > 1023 end
Compare two JIDs, helpful for sorting etc.
String representations are compared, see #to_s
# File lib/xmpp4r/jid.rb, line 107 def <=>(o) to_s <=> o.to_s end
Get the JID's domain
# File lib/xmpp4r/jid.rb, line 125 def domain return nil if @domain.empty? @domain end
Set the JID's domain
# File lib/xmpp4r/jid.rb, line 131 def domain=(v) @domain = v.to_s if USE_STRINGPREP @domain = IDN::Stringprep.nodeprep(@domain) end end
Test if jid is empty
# File lib/xmpp4r/jid.rb, line 157 def empty? to_s.empty? end
Returns a hash value of the String representation (see #to_s)
# File lib/xmpp4r/jid.rb, line 82 def hash return to_s.hash end
Get the JID's node
# File lib/xmpp4r/jid.rb, line 112 def node @node end
Set the JID's node
# File lib/xmpp4r/jid.rb, line 117 def node=(v) @node = v.to_s if USE_STRINGPREP @node = IDN::Stringprep.nodeprep(@node) if @node end end
Get the JID's resource
# File lib/xmpp4r/jid.rb, line 139 def resource @resource end
Set the JID's resource
# File lib/xmpp4r/jid.rb, line 144 def resource=(v) @resource = v.to_s if USE_STRINGPREP @resource = IDN::Stringprep.nodeprep(@resource) end end
Returns a new JID with resource removed.
# File lib/xmpp4r/jid.rb, line 65 def strip JID.new(@node, @domain) end
Removes the resource (sets it to nil)
self
# File lib/xmpp4r/jid.rb, line 73 def strip! @resource = nil self end
Test id jid is strepped
# File lib/xmpp4r/jid.rb, line 162 def stripped? @resource.nil? end
Returns a string representation of the JID
“”
“domain”
“node@domain”
“domain/resource”
“node@domain/resource”
# File lib/xmpp4r/jid.rb, line 55 def to_s s = @domain s = "#{@node}@#{s}" if @node s += "/#{@resource}" if @resource return s end