Class: AgentXmpp::Xmpp::Jid

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/agent_xmpp/xmpp/jid.rb

Overview


Constant Summary collapse

PATTERN =

.….….….….….….….….….….….….….….….….….….….….….….….….……

/^(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node = "", domain = nil, resource = nil) ⇒ Jid

.….….….….….….….….….….….….….….….….….….….….….….….….……

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/agent_xmpp/xmpp/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

Class Method Details

.escape(jid) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



128
129
130
# File 'lib/agent_xmpp/xmpp/jid.rb', line 128

def Jid::escape(jid)
  return jid.to_s.gsub('@', '%')
end

Instance Method Details

#<=>(o) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



83
84
85
# File 'lib/agent_xmpp/xmpp/jid.rb', line 83

def <=>(o)
  to_s <=> o.to_s
end

#==(o) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



78
79
80
# File 'lib/agent_xmpp/xmpp/jid.rb', line 78

def ==(o)
  to_s == o.to_s
end

#domainObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



101
102
103
104
# File 'lib/agent_xmpp/xmpp/jid.rb', line 101

def domain
  return nil if @domain.empty?
  @domain
end

#domain=(v) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



107
108
109
110
111
112
# File 'lib/agent_xmpp/xmpp/jid.rb', line 107

def domain=(v)
  @domain = v.to_s
  if USE_STRINGPREP
    @domain = IDN::Stringprep.nodeprep(@domain)
  end
end

#empty?Boolean

.….….….….….….….….….….….….….….….….….….….….….….….….……

Returns:

  • (Boolean)


133
134
135
# File 'lib/agent_xmpp/xmpp/jid.rb', line 133

def empty?
  to_s.empty?
end

#eql?(o) ⇒ Boolean

.….….….….….….….….….….….….….….….….….….….….….….….….……

Returns:

  • (Boolean)


73
74
75
# File 'lib/agent_xmpp/xmpp/jid.rb', line 73

def eql?(o)
  to_s.eql?(o.to_s)
end

#hashObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



68
69
70
# File 'lib/agent_xmpp/xmpp/jid.rb', line 68

def hash
  return to_s.hash
end

#nodeObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



88
89
90
# File 'lib/agent_xmpp/xmpp/jid.rb', line 88

def node
  @node
end

#node=(v) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



93
94
95
96
97
98
# File 'lib/agent_xmpp/xmpp/jid.rb', line 93

def node=(v)
  @node = v.to_s
  if USE_STRINGPREP
    @node = IDN::Stringprep.nodeprep(@node) if @node
  end
end

#resourceObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



115
116
117
# File 'lib/agent_xmpp/xmpp/jid.rb', line 115

def resource
  @resource
end

#resource=(v) ⇒ Object

.….….….….….….….….….….….….….….….….….….….….….….….….……



120
121
122
123
124
125
# File 'lib/agent_xmpp/xmpp/jid.rb', line 120

def resource=(v)
  @resource = v.to_s
  if USE_STRINGPREP
    @resource = IDN::Stringprep.nodeprep(@resource)
  end
end

#stripObject Also known as: bare

.….….….….….….….….….….….….….….….….….….….….….….….….……



55
56
57
# File 'lib/agent_xmpp/xmpp/jid.rb', line 55

def strip
  Jid.new(@node, @domain)
end

#strip!Object Also known as: bare!

.….….….….….….….….….….….….….….….….….….….….….….….….……



61
62
63
64
# File 'lib/agent_xmpp/xmpp/jid.rb', line 61

def strip!
  @resource = nil
  self
end

#stripped?Boolean Also known as: bared?

.….….….….….….….….….….….….….….….….….….….….….….….….……

Returns:

  • (Boolean)


138
139
140
# File 'lib/agent_xmpp/xmpp/jid.rb', line 138

def stripped?
  @resource.nil?
end

#to_sObject

.….….….….….….….….….….….….….….….….….….….….….….….….……



47
48
49
50
51
52
# File 'lib/agent_xmpp/xmpp/jid.rb', line 47

def to_s
  s = @domain
  s = "#{@node}@#{s}" if @node
  s += "/#{@resource}" if @resource
  return s
end