Sha256: 9a7bafb9b8e5c5d184cb86e208b68d625468e652d0e2ff779947edba88837164

Contents?: true

Size: 902 Bytes

Versions: 37

Compression:

Stored size: 902 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

37 entries across 37 versions & 1 rubygems

Version Path
decidim-verifications-0.27.9 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.8 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.7 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.6 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.10 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.9 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.5 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.8 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.4 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.3 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.7 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.5 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.2 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.1 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.4 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.0 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.3 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.0.rc2 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.27.0.rc1 app/models/decidim/verifications/csv_census/data.rb
decidim-verifications-0.26.2 app/models/decidim/verifications/csv_census/data.rb