class Vines::JID

Constants

NAME_PREP

tools.ietf.org/html/rfc3454#appendix-C

NODE_PREP

tools.ietf.org/html/rfc6122#appendix-A

PATTERN
RESOURCE_PREP

tools.ietf.org/html/rfc6122#appendix-B

Attributes

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

Public Class Methods

new(node, domain=nil, resource=nil) click to toggle source
Calls superclass method
# File lib/vines/jid.rb, line 21
def self.new(node, domain=nil, resource=nil)
  node.is_a?(JID) ? node : super
end
new(node, domain=nil, resource=nil) click to toggle source
# File lib/vines/jid.rb, line 25
def initialize(node, domain=nil, resource=nil)
  @node, @domain, @resource = node, domain, resource

  if @domain.nil? && @resource.nil?
    @node, @domain, @resource = @node.to_s.scan(PATTERN).first
  end
  [@node, @domain].each {|part| part.downcase! if part }

  validate
end

Public Instance Methods

<=>(jid) click to toggle source
# File lib/vines/jid.rb, line 62
def <=>(jid)
  self.to_s <=> jid.to_s
end
bare() click to toggle source

Strip the resource part from this JID and return it as a new JID object. The new JID contains only the optional node part and the required domain part from the original. This JID remains unchanged.

# File lib/vines/jid.rb, line 40
def bare
  JID.new(@node, @domain)
end
bare?() click to toggle source

Return true if this is a bare JID without a resource part.

# File lib/vines/jid.rb, line 45
def bare?
  @resource.nil?
end
domain?() click to toggle source

Return true if this is a domain-only JID without a node or resource part.

# File lib/vines/jid.rb, line 50
def domain?
  !empty? && to_s == @domain
end
empty?() click to toggle source

Return true if this JID is equal to the empty string ''. That is, it's missing the node, domain, and resource parts that form a valid JID. It makes for easier error handling to be able to create JID objects from strings and then check if they're empty rather than nil.

# File lib/vines/jid.rb, line 58
def empty?
  to_s == ''
end
eql?(jid) click to toggle source
# File lib/vines/jid.rb, line 66
def eql?(jid)
  jid.is_a?(JID) && self == jid
end
hash() click to toggle source
# File lib/vines/jid.rb, line 70
def hash
  self.to_s.hash
end
to_s() click to toggle source
# File lib/vines/jid.rb, line 74
def to_s
  s = @domain
  s = "#{@node}@#{s}" if @node
  s = "#{s}/#{@resource}" if @resource
  s
end

Private Instance Methods

validate() click to toggle source
# File lib/vines/jid.rb, line 83
def validate
  [@node, @domain, @resource].each do |part|
    raise ArgumentError, 'jid too long' if (part || '').size > 1023
  end
  raise ArgumentError, 'empty node' if @node && @node.strip.empty?
  raise ArgumentError, 'node contains invalid characters' if @node && @node =~ NODE_PREP
  raise ArgumentError, 'empty resource' if @resource && @resource.strip.empty?
  raise ArgumentError, 'resource contains invalid characters' if @resource && @resource =~ RESOURCE_PREP
  raise ArgumentError, 'empty domain' if @domain == '' && (@node || @resource)
  raise ArgumentError, 'domain contains invalid characters' if @domain && @domain =~ NAME_PREP
end