Sha256: 9b58965eb81e4ce3e1f3b9725807b839aef0332849ddd30d049ea5bf2c5f0c9f

Contents?: true

Size: 923 Bytes

Versions: 6

Compression:

Stored size: 923 Bytes

Contents

# frozen_string_literal: true

require "csv"

module Decidim
  module Verifications
    module CsvCensus
      # A data processor for get emails data form a csv file
      #
      # Enable this methods:
      #
      # - .error with an array of rows with errors in the csv file
      # - .values an array with emails read from the csv file
      #
      # Returns nothing
      class Data
        attr_reader :errors, :values

        def initialize(file)
          @file = file
          @values = []
          @errors = []

          CSV.foreach(@file, encoding: "BOM|UTF-8") do |row|
            process_row(row)
          end
        end

        private

        def process_row(row)
          user_mail = row.first
          if user_mail.present? && user_mail.match?(::Devise.email_regexp)
            values << user_mail
          else
            errors << row
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-verifications-0.29.1 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.29.0 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.29.0.rc4 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.29.0.rc3 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.29.0.rc2 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.29.0.rc1 app/models/decidim/verifications/csv_census/data.rb