Method: Ldaptic.encode
- Defined in:
- lib/ldaptic/escape.rb
.encode(value) ⇒ Object
Encode an object with LDAP semantics. Generally this is just to_s, but dates and booleans get special treatment.
If a symbol is passed in, underscores are replaced by dashes, aiding in bridging the gap between LDAP and Ruby conventions.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ldaptic/escape.rb', line 8 def self.encode(value) if value.respond_to?(:utc) value.dup.utc.strftime("%Y%m%d%H%M%S") + ".%06dZ" % value.usec elsif [true, false].include?(value) value.to_s.upcase elsif value.respond_to?(:dn) value.dn.dup elsif value.kind_of?(Symbol) value.to_s.gsub('_', '-') else value.to_s.dup end end |