def raw_filter raw_data, opts={}
      raw_header = raw_data[header_row].map.with_index do |h, idx|
        is_valid = valid_header?(h)
        {
          idx: idx,
          is_remove: !is_valid,
          is_required: require_header?(h),
          name: is_valid && h.gsub(/\s*/, '').gsub(/!/, '').downcase
        }
      end

      rows = raw_data[(header_row + 1)..-1].map.with_index do |raw, rdx|
        row = {}.with_indifferent_access
        raw_header.each do |h|
          val = raw[h[:idx]]
          next if h[:is_remove]
          if h[:is_required] && val.blank?
            row = {}
            break
          end

          row[h[:name]] = standardize_cell_val val
        end

        next if row.values.all?(&:blank?)

        row[:id] = rdx + 1 if find_columns.include?(:id) && row[:id].blank?
        row
      end.compact
         .reject(&:blank?)
      rows = rows.select do |row|
        if required_columns.present?
          required_columns.all? {|col| row[col].present? }
        else
          true
        end
      end

      rows
    end
def raw_filter raw_data, opts={}
      raw_header = raw_data[header_row].map.with_index do |h, idx|
        is_valid = valid_header?(h)
        {
          idx: idx,
          is_remove: !is_valid,
          is_required: require_header?(h),
          name: is_valid && h.gsub(/\s*/, '').gsub(/!/, '').downcase
        }
      end

      rows = raw_data[(header_row + 1)..-1].map.with_index do |raw, rdx|
        row = {}.with_indifferent_access
        raw_header.each do |h|
          val = raw[h[:idx]]
          next if h[:is_remove]
          if h[:is_required] && val.blank?
            row = {}
            break
          end

          row[h[:name]] = standardize_cell_val val
        end

        next if row.values.all?(&:blank?)

        row[:id] = rdx + 1 if find_columns.include?(:id) && row[:id].blank?
        row
      end.compact
         .reject(&:blank?)
      rows = rows.select do |row|
        if required_columns.present?
          required_columns.all? {|col| row[col].present? }
        else
          true
        end
      end

      rows
    end
Remove uncessary columns and invalid rows from csv format data