Sha256: 56dc1566c93f795defeec7be8f60db0a91a6dde89e3b76dc8226055ade0a201b

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

module RichEmailValidator
  # Validate input file emails and save valid ones to another output file
  class FileValidator
    attr_reader :input_file_path

    class << self
      # Validates input from file
      # @param input_file_path [File]
      # @param [Hash] options
      # @option options [#to_int] :threads_count number of threads that will
      #  be fired simultaneously to calculate the result
      # @return [Array]
      def filter(input_file_path, options = {})
        new(input_file_path, options).filter
      end

      # Validates input from file and write to file
      # @param input_file_path [File]
      # @param output_file_path [File]
      # @param [Hash] options
      # @option options [#to_int] :threads_count number of threads that will
      #  be fired simultaneously to calculate the result
      def export_valid_list(input_file_path, output_file_path, options = {})
        new(input_file_path, options).export_valid_list(output_file_path)
      end
    end

    # Validates input from file
    # @param input_file_path [File]
    # @param [Hash] options
    # @option options [#to_int] :threads_count number of threads that will
    #  be fired simultaneously to calculate the result
    def initialize(input_file_path, options = {})
      @input_file_path = input_file_path
      @options = options
    end

    # Validates input from file
    # @return [Array]
    def filter
      @filtered ||= run_filter
    end

    # Validates input from file and writes to file
    def export_valid_list(output_file_path)
      File.open(output_file_path, 'w') do |file|
        filter.each { |email| file.puts(email) }
      end
    end

    private

    def run_filter
      list = File.readlines(@input_file_path).map(&:chomp)
      ListValidator.filter(list, @options)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rich_email_validator-0.0.1 lib/rich_email_validator/file_validator.rb