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\-]*/
SAFE_CHAR =
/[\x01-\x09\x0B-\x0C\x0E-\x7F]/
SAFE_INIT_CHAR =
/[\x01-\x09\x0B-\x0C\x0E-\x1F\x21-\x39\x3B\x3D-\x7F]/
SAFE_STRING =
/#{SAFE_INIT_CHAR}#{SAFE_CHAR}*/
FILL =
/ */

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GetTextSupport

included

Constructor Details

#initialize(source) ⇒ Parser

Returns a new instance of Parser.



96
97
98
99
100
# File 'lib/active_ldap/ldif.rb', line 96

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.



95
96
97
# File 'lib/active_ldap/ldif.rb', line 95

def ldif
  @ldif
end

Instance Method Details

#parseObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/active_ldap/ldif.rb', line 107

def parse
  return @ldif if @ldif

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

  version = @scanner.scan(/\d+/)
  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