Class: Xrc::Jid
- Inherits:
-
Object
- Object
- Xrc::Jid
- Defined in:
- lib/xrc/jid.rb
Constant Summary collapse
- PATTERN =
/\A(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?\z/
Instance Attribute Summary collapse
-
#domain ⇒ String
Domain section (e.g. example.com in [email protected]/bot).
-
#node ⇒ String
Node section (e.g. alice in [email protected]/bot).
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#resource ⇒ String?
Resource section, which can be omitted (e.g. bot in [email protected]/bot).
Instance Method Summary collapse
-
#==(jid) ⇒ true, false
True if given Jabber ID is same with self Jabber ID.
-
#initialize(raw) ⇒ Jid
constructor
A new instance of Jid.
-
#strip ⇒ String
Jabber ID without resource section.
-
#to_s ⇒ String
Jabber ID, including resource section if any.
Constructor Details
#initialize(raw) ⇒ Jid
Returns a new instance of Jid.
12 13 14 |
# File 'lib/xrc/jid.rb', line 12 def initialize(raw) @raw = raw end |
Instance Attribute Details
#domain ⇒ String
Returns Domain section (e.g. example.com in [email protected]/bot).
22 23 24 |
# File 'lib/xrc/jid.rb', line 22 def domain @domain ||= sections[1] end |
#node ⇒ String
Returns Node section (e.g. alice in [email protected]/bot).
17 18 19 |
# File 'lib/xrc/jid.rb', line 17 def node @node ||= sections[0] end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
7 8 9 |
# File 'lib/xrc/jid.rb', line 7 def raw @raw end |
#resource ⇒ String?
Returns 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.
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 |
#strip ⇒ String
Returns Jabber ID without resource section.
32 33 34 |
# File 'lib/xrc/jid.rb', line 32 def strip "#{node}@#{domain}" end |
#to_s ⇒ String
Returns 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 |