Sha256: bfac8c4746e61c4447bd69dfbabe53376210c28351b0e7cbdf2d6687afc27950

Contents?: true

Size: 642 Bytes

Versions: 35

Compression:

Stored size: 642 Bytes

Contents

# frozen_string_literal: true

module Zizia
  ##
  # A validator for correctly formatted CSV.
  #
  # @example
  #   parser = Parser.new(file: File.open('path/to/my.csv'))
  #
  #   CsvFormatValidator.new.validate(parser: parser)
  #
  # @see http://ruby-doc.org/stdlib-2.0.0/libdoc/csv/rdoc/CSV/MalformedCSVError.html
  class CsvFormatValidator < Validator
    ##
    # @private
    #
    # @see Validator#validate
    def run_validation(parser:, **)
      return [] if CSV.parse(parser.file.read)
    rescue CSV::MalformedCSVError => e
      [Error.new(self.class, e.class, e.message)]
    ensure
      parser.file.rewind
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
zizia-6.0.1 lib/zizia/validators/csv_format_validator.rb
zizia-6.0.0 lib/zizia/validators/csv_format_validator.rb
zizia-5.5.0 lib/zizia/validators/csv_format_validator.rb
zizia-5.4.0 lib/zizia/validators/csv_format_validator.rb
zizia-5.3.0 lib/zizia/validators/csv_format_validator.rb
zizia-5.2.0 lib/zizia/validators/csv_format_validator.rb
zizia-5.1.0 lib/zizia/validators/csv_format_validator.rb
zizia-5.0.1 lib/zizia/validators/csv_format_validator.rb
zizia-5.0.0 lib/zizia/validators/csv_format_validator.rb
zizia-4.6.0.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.5.4.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.5.3.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.5.2.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.5.1.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.4.1.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.4.0.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.3.1.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.2.0.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.1.0.alpha.01 lib/zizia/validators/csv_format_validator.rb
zizia-4.0.4.alpha.01 lib/zizia/validators/csv_format_validator.rb