Class: Jabber::JID
- Inherits:
-
Object
- Object
- Jabber::JID
- Defined in:
- lib/jabber4r/jid.rb
Overview
The Jabber ID class is used to hold a parsed jabber identifier (account+host+resource)
Instance Attribute Summary collapse
-
#host ⇒ Object
The host name (or IP address).
-
#node ⇒ Object
The node (account).
-
#resource ⇒ Object
The resource id.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
Evalutes whether the node, resource and host are the same.
-
#hash ⇒ Object
Override #hash to hash based on the to_s method.
-
#initialize(id) ⇒ JID
constructor
Constructs a JID from the supplied string of the format: node@host (e.g. “[email protected]/laptop”).
- #same_account?(other) ⇒ Boolean
-
#strip_resource ⇒ Object
Removes the resource from this JID.
-
#to_s ⇒ Object
Returns the string (“node@host/resource”) representation of this JID.
Constructor Details
#initialize(id) ⇒ JID
Constructs a JID from the supplied string of the format:
node@host[/resource] (e.g. "[email protected]/laptop")
- id
- String
-
The jabber id string to parse
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jabber4r/jid.rb', line 35 def initialize(id) at_loc = id.index('@') slash_loc = id.index('/') if at_loc.nil? and slash_loc.nil? @host = id end if at_loc @node = id[0,at_loc] host_end = slash_loc ? slash_loc-(at_loc+1) : id.size-(at_loc+1) @host = id[at_loc+1,host_end] @resource = id[slash_loc+1, id.size] if slash_loc end end |
Instance Attribute Details
#host ⇒ Object
The host name (or IP address)
20 21 22 |
# File 'lib/jabber4r/jid.rb', line 20 def host @host end |
#node ⇒ Object
The node (account)
14 15 16 |
# File 'lib/jabber4r/jid.rb', line 14 def node @node end |
#resource ⇒ Object
The resource id
17 18 19 |
# File 'lib/jabber4r/jid.rb', line 17 def resource @resource end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object
Evalutes whether the node, resource and host are the same
- other
- Jabber::JID
-
The other jabber id
- return
- Boolean
-
True if they match
54 55 56 57 |
# File 'lib/jabber4r/jid.rb', line 54 def ==(other) return true if other.node==@node and other.resource==@resource and other.host==@host return false end |
#hash ⇒ Object
Override #hash to hash based on the to_s method
87 88 89 |
# File 'lib/jabber4r/jid.rb', line 87 def hash return to_s.hash end |
#same_account?(other) ⇒ Boolean
59 60 61 62 63 |
# File 'lib/jabber4r/jid.rb', line 59 def same_account?(other) other = JID.to_jid(other) return true if other.node==@node and other.host==@host return false end |
#strip_resource ⇒ Object
Removes the resource from this JID
68 69 70 71 |
# File 'lib/jabber4r/jid.rb', line 68 def strip_resource @resource=nil return self end |
#to_s ⇒ Object
Returns the string (“node@host/resource”) representation of this JID
- return
- String
-
String form of JID
78 79 80 81 82 |
# File 'lib/jabber4r/jid.rb', line 78 def to_s result = (@node.to_s+"@"+@host.to_s) result += ("/"+@resource) if @resource return result end |