summaryrefslogtreecommitdiff
path: root/app/models/card.rb
blob: 594ae43b0a0fd12397007e89081b878faa941b5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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