Class: Brid::CredCard
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
#association ⇒ Object
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])/ return :amex if @number.length == 15 and @number =~ /^3[47]/ return :visa if [13,16].include?(@number.length) and @number =~ /^4/ return :master if @number.length == 16 and @number =~ /^5[1-5]/ return :discover if @number.length == 16 and @number =~ /^6011/ return false
end
|
#invalid_sequential? ⇒ 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
|
#sequential ⇒ Object
9
10
11
12
13
|
# File 'lib/brid/ids/cred_card.rb', line 9
def sequential
@sequential ||= begin
@number[/^(.*).$/, 1]
end
end
|