Class: ActiveLdap::Ldif::Parser

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

Constant Summary collapse

ATTRIBUTE_TYPE_CHARS =
/[a-zA-Z][a-zA-Z0-9\-]*/u
SAFE_CHAR =
/[\x01-\x09\x0B-\x0C\x0E-\x7F]/u
SAFE_INIT_CHAR =
/[\x01-\x09\x0B-\x0C\x0E-\x1F\x21-\x39\x3B\x3D-\x7F]/u
SAFE_STRING =
/#{SAFE_INIT_CHAR}#{SAFE_CHAR}*/u
FILL =
/ */u

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GetTextSupport

included

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



85
86
87
88
89
# File 'lib/active_ldap/ldif.rb', line 85

def initialize(source)
  @ldif = nil
  source = source.to_s if source.is_a?(LDIF)
  @source = source
end

Instance Attribute Details

#ldifObject (readonly)

Returns the value of attribute ldif.



84
85
86
# File 'lib/active_ldap/ldif.rb', line 84

def ldif
  @ldif
end

Instance Method Details

#parseObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/active_ldap/ldif.rb', line 96

def parse
  return @ldif if @ldif

  @scanner = Scanner.new(@source)
  raise version_spec_is_missing unless @scanner.scan(/version:/u)
  @scanner.scan(FILL)

  version = @scanner.scan(/\d+/u)
  raise version_number_is_missing if version.nil?

  version = Integer(version)
  raise unsupported_version(version) if version != 1

  raise separator_is_missing unless @scanner.scan_separators

  records = parse_records

  @ldif = LDIF.new(records)
end