Sha256: 5544e0f5c9ee08a4525e8feed1d41f951edcb60384e67373edcd523acf6c180c

Contents?: true

Size: 622 Bytes

Versions: 12

Compression:

Stored size: 622 Bytes

Contents

module Valigator
  module CSV
    module FieldValidators
      class Date < Base

        def valid?(value)
          return true if allow_blank and blank? value

          parse value
          true
        rescue ArgumentError
          false
        end



        def error_type
          'invalid_date'
        end



        def error_message
          'Invalid date field'
        end



        private

        def format
          @options[:format]
        end



        def parse(value)
          format ? ::Date.strptime(value.to_s, format) : ::Date.parse(value.to_s)
        end

      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
valigator-csv-4.0.2 lib/valigator/csv/field_validators/date.rb
valigator-csv-4.0.1 lib/valigator/csv/field_validators/date.rb
valigator-csv-4.0 lib/valigator/csv/field_validators/date.rb
valigator-csv-3.0 lib/valigator/csv/field_validators/date.rb
valigator-csv-2.0.1 lib/valigator/csv/field_validators/date.rb
valigator-csv-2.0 lib/valigator/csv/field_validators/date.rb
valigator-csv-1.5.1 lib/valigator/csv/field_validators/date.rb
valigator-csv-1.5.0 lib/valigator/csv/field_validators/date.rb
valigator-csv-1.4.1 lib/valigator/csv/field_validators/date.rb
valigator-csv-1.4.0 lib/valigator/csv/field_validators/date.rb
valigator-csv-1.3.2 lib/valigator/csv/field_validators/date.rb
valigator-csv-1.3.1 lib/valigator/csv/field_validators/date.rb