# File lib/active_ldap/distinguished_name.rb, line 161
161: def escape_value(value)
162: if /(\A | \z)/.match(value)
163: '"' + value.gsub(/([\\\"])/, '\\\1') + '"'
164: else
165: value.gsub(/([,=\+<>#;\\\"])/, '\\\1')
166: end
167: end
# File lib/active_ldap/distinguished_name.rb, line 185
185: def +(other)
186: self.class.new(*(@rdns + other.rdns))
187: end
# File lib/active_ldap/distinguished_name.rb, line 189
189: def -(other)
190: rdns = @rdns.dup
191: normalized_rdns = normalize(@rdns)
192: normalize(other.rdns).reverse_each do |rdn|
193: if rdn == normalized_rdns.pop
194: rdns.pop
195: else
196: raise ArgumentError, _("%s isn't sub DN of %s") % [other, self]
197: end
198: end
199: self.class.new(*rdns)
200: end
# File lib/active_ldap/distinguished_name.rb, line 202
202: def <<(rdn)
203: @rdns << rdn
204: self
205: end
# File lib/active_ldap/distinguished_name.rb, line 216
216: def <=>(other)
217: other = DN.parse(other) if other.is_a?(String)
218: return nil unless other.is_a?(self.class)
219: normalize_for_comparing(@rdns) <=>
220: normalize_for_comparing(other.rdns)
221: end
# File lib/active_ldap/distinguished_name.rb, line 223
223: def ==(other)
224: case other
225: when self.class
226: normalize(@rdns) == normalize(other.rdns)
227: when String
228: parsed_other = nil
229: begin
230: parsed_other = self.class.parse(other)
231: rescue DistinguishedNameInvalid
232: return false
233: end
234: self == parsed_other
235: else
236: false
237: end
238: end
# File lib/active_ldap/distinguished_name.rb, line 181
181: def blank?
182: @rdns.blank?
183: end
# File lib/active_ldap/distinguished_name.rb, line 240
240: def eql?(other)
241: other.is_a?(self.class) and
242: normalize(@rdns).to_s.eql?(normalize(other.rdns).to_s)
243: end
# File lib/active_ldap/distinguished_name.rb, line 245
245: def hash
246: normalize(@rdns).to_s.hash
247: end
# File lib/active_ldap/distinguished_name.rb, line 211
211: def parent
212: return nil if @rdns.size <= 1
213: self.class.new(*@rdns[1..1])
214: end
# File lib/active_ldap/distinguished_name.rb, line 264
264: def to_human_readable_format
265: to_s.inspect
266: end
# File lib/active_ldap/distinguished_name.rb, line 249
249: def to_s
250: klass = self.class
251: @rdns.collect do |rdn|
252: rdn.sort_by do |type, value|
253: type.upcase
254: end.collect do |type, value|
255: "#{type}=#{klass.escape_value(value)}"
256: end.join("+")
257: end.join(",")
258: end
# File lib/active_ldap/distinguished_name.rb, line 269
269: def normalize(rdns)
270: rdns.collect do |rdn|
271: normalized_rdn = {}
272: rdn.each do |key, value|
273: normalized_rdn[key.upcase] = value.upcase
274: end
275: normalized_rdn
276: end
277: end
# File lib/active_ldap/distinguished_name.rb, line 279
279: def normalize_for_comparing(rdns)
280: normalize(rdns).collect do |rdn|
281: rdn.sort_by do |key, value|
282: key
283: end
284: end.collect do |key, value|
285: [key, value]
286: end
287: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.