def convert(record)
  rs, fs, vs, crlf_re, iconv =
    RECORD_SEPARATOR, FIELD_SEPARATOR, VALUE_SEPARATOR, CRLF_RE, TO_LATIN1
  dbm = ["ID#{fs}#{record.id}"]
  record.struct.each { |field, struct|
    struct_values = struct[:values]
    struct_values.default = []
    strings = struct[:elements].map { |element|
      values = []
      struct_values[element].each { |value|
        if value
          value = value.strip.gsub(crlf_re, ' ')
          values << value unless value.empty?
        end
      }
      values.empty? ? struct[:empty] : values.join(vs)
    }
    dbm << "#{field.to_s.upcase}#{fs}#{iconv.iconv(struct[:string] % strings)}"
  }
  dbm << rs << CRLF
  dbm.join(CRLF)
end