Class: Braspag::CreditCard::ExpiratorValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/cbraspag/payment/credit_card.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/cbraspag/payment/credit_card.rb', line 151

def validate_each(record, attribute, value)
  begin
    year = record.year.try(:to_i)
    year = "20#{year}".to_i if year && year.to_s.size == 2

    month = record.month.try(:to_i)

    Date.new(year, month) if year && month
  rescue ArgumentError
    record.errors.add attribute, "invalid date"
  end
end