Class: Dolla::CardType

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

Constant Summary collapse

PREFIXES =
{
  1 => [ 4 ], #Bank code for VISA
  2 => [ *51..55 ], #Bank code for MC
  3 => [ 34, 37 ], #Bank code for AMEX
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ CardType

Returns a new instance of CardType.



11
12
13
14
# File 'lib/dolla/card_type.rb', line 11

def initialize(args = {})
  @name = args[:name]
  @bank_code = args[:bank_code]
end

Instance Attribute Details

#bank_codeObject

Returns the value of attribute bank_code.



9
10
11
# File 'lib/dolla/card_type.rb', line 9

def bank_code
  @bank_code
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/dolla/card_type.rb', line 9

def name
  @name
end

Class Method Details

.card_code_for_number(number) ⇒ Object



16
17
18
19
20
# File 'lib/dolla/card_type.rb', line 16

def self.card_code_for_number number
  codes = self.all.map do |card_type|
    PREFIXES[ card_type.bank_code ].map { |prefix| card_type if number =~ /\A#{ prefix }/ }
  end.flatten.compact.uniq.last
end