Sha256: c082a4bc573d42222e56a50c06b639ea667dd2225c81c765567d6aab0faca429

Contents?: true

Size: 460 Bytes

Versions: 7

Compression:

Stored size: 460 Bytes

Contents

module ActiveModel
  module Validations
    class CreditCardNumberValidator < EachValidator

      def validate_each(record, attribute, value)
        brands = options.fetch(:brands, :any)
        record.errors.add(attribute) unless credit_card_valid?(value, brands == :any ? [] : Array.wrap(brands) )
      end

      def credit_card_valid?(number, brands = [])
        CreditCardValidations::Detector.new(number).valid?(*brands)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
credit_card_validations-1.4.7 lib/active_model/credit_card_number_validator.rb
credit_card_validations-1.4.6 lib/active_model/credit_card_number_validator.rb
credit_card_validations-1.4.5 lib/active_model/credit_card_number_validator.rb
credit_card_validations-1.4.4 lib/active_model/credit_card_number_validator.rb
credit_card_validations-1.4.3 lib/active_model/credit_card_number_validator.rb
credit_card_validations-1.4.2 lib/active_model/credit_card_number_validator.rb
credit_card_validations-1.4.1 lib/active_model/credit_card_number_validator.rb