Class: RealEx::Card

Inherits:
Object
  • Object
show all
Includes:
Initializer
Defined in:
lib/real_ex/card.rb

Instance Method Summary collapse

Methods included from Initializer

included, #initialize

Instance Method Details

#clean_nameObject



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

def clean_name
  cardholder_name.gsub(/[^a-zA-Z0-9 ]/, '')
end

#passes_luhn_check?Boolean

The luhn check is a check to see if a credit card is actually a credit card or not

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
# File 'lib/real_ex/card.rb', line 9

def passes_luhn_check?
  odd = true
  luhn = number.to_s.gsub(/\D/,'').reverse.split('').collect { |d|
    d = d.to_i
    d *= 2 if odd = !odd
    d > 9 ? d - 9 : d
  }.inject(0) { |sum,number| sum + number }
  luhn % 10 == 0
end