diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/card.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models/card.rb b/app/models/card.rb index ae2b1e5..594ae43 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -1,3 +1,20 @@ +# frozen_string_literal: true + +# Card +# number: string +# expiration_month: integer +# expiration_year: integer +# expiration_day: integer +# security_code: integer class Card < ApplicationRecord belongs_to :user_account + validates :number, presence: true, uniqueness: true, length: { is: 16 } + validates :expiration_year, presence: true, numericality: { greater_than: 1970 } + validates :expiration_month, presence: true, inclusion: { in: 1..12 } + validates :expiration_day, presence: true, inclusion: { in: 1..31 } + validates :security_code, presence: true + + def expiration_date + "#{expiration_day}/#{expiration_month}/#{expiration_year}" + end end |