# module ActiveLdap::Ldif::Attribute

### Constants

SIZE

### Public Instance Methods

binary_value?(value) click to toggle source

    # File lib/active_ldap/ldif.rb, line 34
    def binary_value?(value)
      if value.respond_to?(:encoding)
        return true if value.encoding == Encoding.find("ascii-8bit")
      end
      if /\A#{Parser::SAFE_STRING}\z/ =~ value
        false
      else
        true
      end
    end

encode(name, value) click to toggle source

    # File lib/active_ldap/ldif.rb, line 45
    def encode(name, value)
      return "#{name}:\n" if value.blank?
      result = "#{name}:"

      value = value.to_s unless value.is_a?(String)
      if value[-1, 1] == ' ' or binary_value?(value)
        result << ":"
        value = [value].pack("m").gsub(/\n/, '')
      end
      result << " "

      first_line_value_size = SIZE - result.size
      if value.size > first_line_value_size
        first_line_value = value[0, first_line_value_size]
        rest_value = value[first_line_value_size..-1]
      else
        first_line_value = value
        rest_value = nil
      end

      result << "#{first_line_value}\n"
      return result if rest_value.nil?

      rest_value.scan(/.{1,#{SIZE - 1}}/).each do |line| # FIXME
        result << " #{line}\n"
      end
      result
    end

normalize_value(value, result=[]) click to toggle source

    # File lib/active_ldap/ldif.rb, line 74
    def normalize_value(value, result=[])
      case value
      when Array
        value.each {|val| normalize_value(val, result)}
      when Hash
        value.each do |option, val|
          normalize_value(val).each do |options, v|
            result << [[option] + options, v]
          end
        end
        result
      else
        result << [[], value]
      end
      result
    end