Class: ActiveLdap::DistinguishedName::Parser

Inherits:
Object
  • Object
show all
Includes:
GetTextSupport
Defined in:
lib/active_ldap/distinguished_name.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GetTextSupport

included

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#dnObject (readonly)

Returns the value of attribute dn.



10
11
12
# File 'lib/active_ldap/distinguished_name.rb', line 10

def dn
  @dn
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_ldap/distinguished_name.rb', line 20

def parse
  return @dn if @dn

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

  scanner.scan(/\s*/)
  raise rdn_is_missing if scanner.scan(/\s*\+\s*/)
  raise name_component_is_missing if scanner.scan(/\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(/\s*\+\s*/)
      raise rdn_is_missing if scanner.eos?
    elsif scanner.scan(/\s*\,\s*/)
      rdns << rdn
      rdn = {}
      raise name_component_is_missing if scanner.eos?
    else
      scanner.scan(/\s*/)
      rdns << rdn if scanner.eos?
    end
  end

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