Class: Brid::CredCard

Inherits:
GenericID show all
Defined in:
lib/brid/ids/cred_card.rb

Instance Attribute Summary

Attributes inherited from GenericID

#number

Instance Method Summary collapse

Methods inherited from GenericID

#check_digits, #check_digits_length, #freeze, #number_length, #to_s, #valid?

Constructor Details

#initialize(number) ⇒ CredCard

Returns a new instance of CredCard.



3
4
5
6
7
# File 'lib/brid/ids/cred_card.rb', line 3

def initialize number
  @number = clear_number(number)

  @number = @number.rjust! 14, '0' unless (14..19).include? @number.length
end

Instance Method Details

#associationObject



15
16
17
18
19
20
21
22
# File 'lib/brid/ids/cred_card.rb', line 15

def association
  return :dinners  if @number.length == 14 and @number =~ /^3(0[0-5]|[68])/   # 300xxx-305xxx, 36xxxx, 38xxxx
  return :amex     if @number.length == 15 and @number =~ /^3[47]/            # 34xxxx, 37xxxx
  return :visa     if [13,16].include?(@number.length) and @number =~ /^4/    # 4xxxxx
  return :master   if @number.length == 16 and @number =~ /^5[1-5]/           # 51xxxx-55xxxx
  return :discover if @number.length == 16 and @number =~ /^6011/             # 6011xx
  return false
end

#invalid_sequential?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/brid/ids/cred_card.rb', line 24

def invalid_sequential?
  @invalid_sequential ||=begin
    association != false
  end
end

#sequentialObject



9
10
11
12
13
# File 'lib/brid/ids/cred_card.rb', line 9

def sequential 
  @sequential ||= begin
    @number[/^(.*).$/, 1]
  end
end