Class: Xrc::Jid

Inherits:
Object
  • Object
show all
Defined in:
lib/xrc/jid.rb

Constant Summary collapse

PATTERN =
/\A(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw) ⇒ Jid

Returns a new instance of Jid.

Examples:

Xrc::Jid.new("[email protected]/bot")

Parameters:

  • raw (String)

    Jabber ID



12
13
14
# File 'lib/xrc/jid.rb', line 12

def initialize(raw)
  @raw = raw
end

Instance Attribute Details

#domainString

Returns Domain section (e.g. example.com in [email protected]/bot).

Returns:



22
23
24
# File 'lib/xrc/jid.rb', line 22

def domain
  @domain ||= sections[1]
end

#nodeString

Returns Node section (e.g. alice in [email protected]/bot).

Returns:



17
18
19
# File 'lib/xrc/jid.rb', line 17

def node
  @node ||= sections[0]
end

#rawObject (readonly)

Returns the value of attribute raw.



7
8
9
# File 'lib/xrc/jid.rb', line 7

def raw
  @raw
end

#resourceString?

Returns Resource section, which can be omitted (e.g. bot in [email protected]/bot).

Returns:

  • (String, nil)

    Resource section, which can be omitted (e.g. bot in [email protected]/bot)



27
28
29
# File 'lib/xrc/jid.rb', line 27

def resource
  @resource ||= sections[2]
end

Instance Method Details

#==(jid) ⇒ true, false

Returns True if given Jabber ID is same with self Jabber ID.

Returns:

  • (true, false)

    True if given Jabber ID is same with self Jabber ID



44
45
46
47
# File 'lib/xrc/jid.rb', line 44

def ==(jid)
  jid = Jid.new(jid) unless jid.is_a?(Jid)
  to_s == jid.to_s || strip == jid.strip
end

#stripString

Returns Jabber ID without resource section.

Returns:

  • (String)

    Jabber ID without resource section



32
33
34
# File 'lib/xrc/jid.rb', line 32

def strip
  "#{node}@#{domain}"
end

#to_sString

Returns Jabber ID, including resource section if any.

Returns:

  • (String)

    Jabber ID, including resource section if any



37
38
39
40
41
# File 'lib/xrc/jid.rb', line 37

def to_s
  str = strip
  str << "/#{resource}" if resource
  str
end