Class: Vines::JID
Constant Summary collapse
- PATTERN =
/\A(?:([^@]*)@)??([^@\/]*)(?:\/(.*?))?\Z/.freeze
- NODE_PREP =
/[[:cntrl:] "&'\/:<>@]/.freeze
- NAME_PREP =
/[[:cntrl:] ]/.freeze
- RESOURCE_PREP =
/[[:cntrl:]]/.freeze
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#resource ⇒ Object
Returns the value of attribute resource.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(jid) ⇒ Object
-
#bare ⇒ Object
Strip the resource part from this JID and return it as a new JID object.
-
#bare? ⇒ Boolean
Return true if this is a bare JID without a resource part.
-
#domain? ⇒ Boolean
Return true if this is a domain-only JID without a node or resource part.
-
#empty? ⇒ Boolean
Return true if this JID is equal to the empty string ”.
- #eql?(jid) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(node, domain = nil, resource = nil) ⇒ JID
constructor
A new instance of JID.
- #to_s ⇒ Object
Constructor Details
#initialize(node, domain = nil, resource = nil) ⇒ JID
Returns a new instance of JID.
25 26 27 28 29 30 31 32 33 34 |
# 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 |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
18 19 20 |
# File 'lib/vines/jid.rb', line 18 def domain @domain end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
18 19 20 |
# File 'lib/vines/jid.rb', line 18 def node @node end |
#resource ⇒ Object
Returns the value of attribute resource.
18 19 20 |
# File 'lib/vines/jid.rb', line 18 def resource @resource end |
Class Method Details
.new(node, domain = nil, resource = nil) ⇒ Object
21 22 23 |
# File 'lib/vines/jid.rb', line 21 def self.new(node, domain=nil, resource=nil) node.is_a?(JID) ? node : super end |
Instance Method Details
#<=>(jid) ⇒ Object
62 63 64 |
# File 'lib/vines/jid.rb', line 62 def <=>(jid) self.to_s <=> jid.to_s end |
#bare ⇒ Object
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.
40 41 42 |
# File 'lib/vines/jid.rb', line 40 def JID.new(@node, @domain) end |
#bare? ⇒ Boolean
Return true if this is a bare JID without a resource part.
45 46 47 |
# File 'lib/vines/jid.rb', line 45 def @resource.nil? end |
#domain? ⇒ Boolean
Return true if this is a domain-only JID without a node or resource part.
50 51 52 |
# File 'lib/vines/jid.rb', line 50 def domain? !empty? && to_s == @domain end |
#empty? ⇒ Boolean
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.
58 59 60 |
# File 'lib/vines/jid.rb', line 58 def empty? to_s == '' end |
#eql?(jid) ⇒ Boolean
66 67 68 |
# File 'lib/vines/jid.rb', line 66 def eql?(jid) jid.is_a?(JID) && self == jid end |
#hash ⇒ Object
70 71 72 |
# File 'lib/vines/jid.rb', line 70 def hash self.to_s.hash end |
#to_s ⇒ Object
74 75 76 77 78 79 |
# File 'lib/vines/jid.rb', line 74 def to_s s = @domain s = "#{@node}@#{s}" if @node s = "#{s}/#{@resource}" if @resource s end |