# File lib/net/ldap/dataset.rb, line 76
76: def initialize
77: @comments = []
78: end
# File lib/net/ldap/dataset.rb, line 38
38: def self.read_ldif io
39: ds = Dataset.new
40: io = IOFilter.new(io)
41:
42: line = io.gets
43: dn = nil
44:
45: while line
46: new_line = io.gets
47: if new_line =~ /^[\s]+/
48: line << " " << $'
49: else
50: nextline = new_line
51:
52: if line =~ /^\#/
53: ds.comments << line
54: elsif line =~ /^dn:[\s]*/
55: dn = $'
56: ds[dn] = Hash.new {|k,v| k[v] = []}
57: elsif line.length == 0
58: dn = nil
59: elsif line =~ /^([^:]+):([\:]?)[\s]*/
60: # $1 is the attribute name
61: # $2 is a colon iff the attr-value is base-64 encoded
62: # $' is the attr-value
63: # Avoid the Base64 class because not all Ruby versions have it.
64: attrvalue = ($2 == ":") ? $'.unpack('m').shift : $'
65: ds[dn][$1.downcase.intern] << attrvalue
66: end
67:
68: line = nextline
69: end
70: end
71:
72: ds
73: end
# File lib/net/ldap/dataset.rb, line 81
81: def to_ldif
82: ary = []
83: ary += (@comments || [])
84: keys.sort.each do |dn|
85: ary << "dn: #{dn}"
86:
87: self[dn].keys.map {|sym| sym.to_s}.sort.each do |attr|
88: self[dn][attr.intern].each {|val| ary << "#{attr}: #{val}" }
89: end
90:
91: ary << ""
92: end
93: block_given? and ary.each {|line| yield line}
94: ary
95: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.