Class: PgCreditcard

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_creditcard.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ PgCreditcard

Returns a new instance of PgCreditcard.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
11
12
# File 'lib/pg_creditcard.rb', line 5

def initialize(options)
  raise ArgumentError if options.nil?
  @name   = options[:name]
  @number = options[:number]
  @month  = options[:month]
  @year   = set_year(options[:year])
  @cvv    = options[:cvv]
end

Instance Method Details

#cardexpmonthObject



37
38
39
# File 'lib/pg_creditcard.rb', line 37

def cardexpmonth
  @month
end

#cardexpyearObject



41
42
43
# File 'lib/pg_creditcard.rb', line 41

def cardexpyear
  @year[2..3]
end

#cardholderObject



29
30
31
# File 'lib/pg_creditcard.rb', line 29

def cardholder
  @name
end

#cardnumberObject



33
34
35
# File 'lib/pg_creditcard.rb', line 33

def cardnumber
  @number
end

#expired?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/pg_creditcard.rb', line 23

def expired?
  today = Time.now
  expiry = Time.new(@year, @month, days_in_a_month(@year, @month))
  today > expiry
end

#typeObject



14
15
16
17
# File 'lib/pg_creditcard.rb', line 14

def type
  return nil if @number.nil?
  @type ||= @number.to_s.creditcard_type
end

#valid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pg_creditcard.rb', line 19

def valid?
  @number.to_s.creditcard?
end