39: def Dataset::read_ldif io
40: ds = Dataset.new
41:
42: line = io.gets && chomp
43: dn = nil
44:
45: while line
46: io.gets and chomp
47: if $_ =~ /^[\s]+/
48: line << " " << $'
49: else
50: nextline = $_
51:
52: if line =~ /^\#/
53: ds.comments << line
54: elsif line =~ /^dn:[\s]*/i
55: dn = $'
56: ds[dn] = Hash.new {|k,v| k[v] = []}
57: elsif line.length == 0
58: dn = nil
59: elsif line =~ /^([^:]+):([\:]?)[\s]*/
60:
61:
62:
63:
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