Sha256: 581045cf0a6c1ac2ad26df93edf288e7e8d76c6aed0ad956bfd212b6e8ccf50a

Contents?: true

Size: 838 Bytes

Versions: 6

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module DirectVerifications
    module Parsers
      # Abstract class all concrete parsers should inherit from. They are expected to implement
      # #header, #lines, and #parse_data methods.
      class BaseParser
        EMAIL_REGEXP = /([A-Z0-9+._-]+@[A-Z0-9._-]+\.[A-Z0-9_-]+)\b/i.freeze

        def initialize(txt)
          @txt = txt
          @emails = {}
        end

        def to_h
          lines.each do |line|
            EMAIL_REGEXP.match(line) do |match|
              email = normalize(match[0])
              emails[email] = parse_data(email, line, header)
            end
          end

          emails
        end

        private

        attr_reader :txt, :emails

        def normalize(value)
          value.to_s.downcase
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-direct_verifications-1.2.1 lib/decidim/direct_verifications/parsers/base_parser.rb
decidim-direct_verifications-1.2 lib/decidim/direct_verifications/parsers/base_parser.rb
decidim-direct_verifications-1.0.2 lib/decidim/direct_verifications/parsers/base_parser.rb
decidim-direct_verifications-1.0.1 lib/decidim/direct_verifications/parsers/base_parser.rb
decidim-direct_verifications-1.1 lib/decidim/direct_verifications/parsers/base_parser.rb
decidim-direct_verifications-1.0 lib/decidim/direct_verifications/parsers/base_parser.rb