class ActiveLdap::DistinguishedName::Parser

Constants

ATTRIBUTE_TYPE_RE
HEX_PAIR
HEX_STRING_RE
PAIR_RE
STRING_CHARS_RE

Attributes

dn[R]

Public Class Methods

new(source) click to toggle source
# File lib/active_ldap/distinguished_name.rb, line 11
def initialize(source)
  @dn = nil
  source = source.to_s if source.is_a?(DN)
  unless source.is_a?(String)
    raise DistinguishedNameInputInvalid.new(source)
  end
  @source = source
end

Public Instance Methods

parse() click to toggle source
# File lib/active_ldap/distinguished_name.rb, line 20
def parse
  return @dn if @dn

  rdns = []
  scanner = StringScanner.new(@source)

  scanner.scan(%r\s*/)
  raise rdn_is_missing if scanner.scan(%r\s*\+\s*/)
  raise name_component_is_missing if scanner.scan(%r\s*,\s*/)

  rdn = {}
  until scanner.eos?
    type = scan_attribute_type(scanner)
    skip_attribute_type_and_value_separator(scanner)
    value = scan_attribute_value(scanner)
    rdn[type] = value
    if scanner.scan(%r\s*\+\s*/)
      raise rdn_is_missing if scanner.eos?
    elsif scanner.scan(%r\s*\,\s*/)
      rdns << rdn
      rdn = {}
      raise name_component_is_missing if scanner.eos?
    else
      scanner.scan(%r\s*/)
      rdns << rdn if scanner.eos?
    end
  end

  @dn = DN.new(*rdns)
  @dn
end