Class: Dolla::CardType
- Inherits:
-
Object
- Object
- Dolla::CardType
- 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
-
#bank_code ⇒ Object
Returns the value of attribute bank_code.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ CardType
constructor
A new instance of CardType.
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_code ⇒ Object
Returns the value of attribute bank_code.
9 10 11 |
# File 'lib/dolla/card_type.rb', line 9 def bank_code @bank_code end |
#name ⇒ Object
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 |