Method: Blather::JID#initialize

Defined in:
lib/blather/jid.rb

#initialize(jid) ⇒ Blather::JID #initialize(jid) ⇒ Blather::JID #initialize(node, domain = nil, resource = nil) ⇒ Blather::JID

Create a new JID object

Overloads:

  • #initialize(jid) ⇒ Blather::JID

    Passes the jid object right back out

    Parameters:

  • #initialize(jid) ⇒ Blather::JID

    Creates a new JID parsed out of the provided jid (“node@domain/resource”)

    Parameters:

    • jid (String)

      a jid in the standard format

  • #initialize(node, domain = nil, resource = nil) ⇒ Blather::JID

    Creates a new JID

    Parameters:

    • node (String)

      the node of the JID

    • domian (String, nil)

      the domain of the JID

    • resource (String, nil) (defaults to: nil)

      the resource of the JID

Raises:

  • (ArgumentError)

    if the parts of the JID are too large (1023 bytes)



77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/blather/jid.rb', line 77

def initialize(node, domain = nil, resource = nil)
  @resource = resource
  @domain = domain
  @node = node

  if @domain.nil? && @resource.nil?
    @node, @domain, @resource = @node.to_s.scan(PATTERN).first
  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