Sha256: baf5f86fc90a98fa44e54004873db2fd1ae87fb5fa3b442a8fb45c1ed6513ee1

Contents?: true

Size: 899 Bytes

Versions: 4

Compression:

Stored size: 899 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 readed from the csv file
      #
      # Returns nothing
      class Data
        attr_reader :errors, :values
        def initialize(file)
          @file = file
          @values = []
          @errors = []

          CSV.foreach(@file) 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

4 entries across 4 versions & 1 rubygems

Version Path
decidim-verifications-0.20.1 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.20.0 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.19.1 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.19.0 app/models/decidim/verifications/csv_census/data.rb