class Jabber::JID

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

Constants

PATTERN
USE_STRINGPREP

Public Class Methods

escape(jid) click to toggle source

Escape JID

# File lib/xmpp4r/jid.rb, line 152
def JID::escape(jid)
  return jid.to_s.gsub('@', '%')
end
new(node = "", domain = nil, resource = nil) click to toggle source

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

Public Instance Methods

<=>(o) click to toggle source

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
==(o) click to toggle source

Ccompare to another JID

String representations are compared, see #to_s

# File lib/xmpp4r/jid.rb, line 98
def ==(o)
  to_s == o.to_s
end
bare()
Alias for: strip
bare!()
Alias for: strip!
bared?()
Alias for: stripped?
domain() click to toggle source

Get the JID's domain

# File lib/xmpp4r/jid.rb, line 125
def domain
  return nil if @domain.empty?
  @domain
end
domain=(v) click to toggle source

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
empty?() click to toggle source

Test if jid is empty

# File lib/xmpp4r/jid.rb, line 157
def empty?
  to_s.empty?
end
eql?(o) click to toggle source

Ccompare to another JID

String representations are compared, see #to_s

# File lib/xmpp4r/jid.rb, line 90
def eql?(o)
  to_s.eql?(o.to_s)
end
hash() click to toggle source

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
node() click to toggle source

Get the JID's node

# File lib/xmpp4r/jid.rb, line 112
def node
  @node
end
node=(v) click to toggle source

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
resource() click to toggle source

Get the JID's resource

# File lib/xmpp4r/jid.rb, line 139
def resource
  @resource
end
resource=(v) click to toggle source

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
strip() click to toggle source

Returns a new JID with resource removed.

return
JID
# File lib/xmpp4r/jid.rb, line 65
def strip
  JID.new(@node, @domain)
end
Also aliased as: bare
strip!() click to toggle source

Removes the resource (sets it to nil)

return
JID

self

# File lib/xmpp4r/jid.rb, line 73
def strip!
  @resource = nil
  self
end
Also aliased as: bare!
stripped?() click to toggle source

Test id jid is strepped

# File lib/xmpp4r/jid.rb, line 162
def stripped?
  @resource.nil?
end
Also aliased as: bared?
to_s() click to toggle source

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