Class Jabber::JID
In: lib/xmpp4r/jid.rb
Parent: Object

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, …

Methods

<=>   eql?   hash   new   strip   strip!   to_s  

Included Modules

Comparable

Attributes

domain  [R] 
node  [R] 
resource  [R] 

Public Class methods

Create a new JID. If called as new(‘a@b/c’), parse the string and split (node, domain, resource)

[Source]

    # File lib/xmpp4r/jid.rb, line 19
19:     def initialize(node = nil, domain = nil, resource = nil)
20:       if node.kind_of? JID
21:         @node = node.node
22:         @domain = node.domain
23:         @resource = node.resource
24:       else
25:         @resource = resource
26:         @domain = domain
27:         @node = node
28:         if domain.nil?
29:           if not node.nil?
30:             if node.include?('@')
31:               @node, @domain = node.split('@',2)
32:               if @domain.include?('/')
33:                 @domain, @resource = @domain.split('/',2)
34:               end
35:             elsif node.include?('/')
36:               @domain, @resource = @node.split('/',2)
37:             else
38:               @domain = node
39:               @node = nil
40:             end
41:           end
42:         end
43:       end
44:     end

Public Instance methods

Compare two JIDs, helpful for sorting etc.

String representations are compared, see JID#to_s

[Source]

    # File lib/xmpp4r/jid.rb, line 96
96:     def <=>(o)
97:       to_s <=> o.to_s
98:     end

Ccompare to another JID

String representations are compared, see JID#to_s

[Source]

    # File lib/xmpp4r/jid.rb, line 87
87:     def eql?(o)
88:       to_s.eql?(o.to_s)
89:     end

Returns a hash value of the String representation (see JID#to_s)

[Source]

    # File lib/xmpp4r/jid.rb, line 79
79:     def hash
80:       return to_s.hash
81:     end

Returns a new JID with resource removed.

return:[JID]

[Source]

    # File lib/xmpp4r/jid.rb, line 64
64:     def strip
65:       JID::new(@node, @domain)
66:     end

Remove the resource of this object

return:[JID] self

[Source]

    # File lib/xmpp4r/jid.rb, line 71
71:     def strip!
72:       @resource = nil
73:       self
74:     end

Returns a string representation of the JID

  • ""
  • "domain"
  • "node@domain"
  • "domain/resource"
  • "node@domain/resource"

[Source]

    # File lib/xmpp4r/jid.rb, line 53
53:     def to_s
54:       s = ''
55:       s = "#{@node}@" if not @node.nil?
56:       s += @domain if not @domain.nil?
57:       s += "/#{@resource}" if not @resource.nil?
58:       return s
59:     end

[Validate]