Class: Iz::CreditCard
- Inherits:
-
Object
- Object
- Iz::CreditCard
- Defined in:
- lib/iz/credit_card.rb
Constant Summary collapse
- REGEX =
/^(?:(4[0-9]{12}(?:[0-9]{3})?)|(5[1-5][0-9]{14})|(6(?:011|5[0-9]{2})[0-9]{12})|(3[47][0-9]{13})|(3(?:0[0-5]|[68][0-9])[0-9]{11})|((?:2131|1800|35[0-9]{3})[0-9]{11}))$/
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(credit_card_number) ⇒ CreditCard
constructor
A new instance of CreditCard.
- #valid? ⇒ Boolean
Constructor Details
#initialize(credit_card_number) ⇒ CreditCard
Returns a new instance of CreditCard.
7 8 9 |
# File 'lib/iz/credit_card.rb', line 7 def initialize(credit_card_number) self.value = credit_card_number end |
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
5 6 7 |
# File 'lib/iz/credit_card.rb', line 5 def value @value end |
Class Method Details
.is_credit_card?(value) ⇒ Boolean
15 16 17 18 |
# File 'lib/iz/credit_card.rb', line 15 def self.is_credit_card?(value) return false unless value value.to_s =~ REGEX end |
Instance Method Details
#valid? ⇒ Boolean
11 12 13 |
# File 'lib/iz/credit_card.rb', line 11 def valid? !!Iz::CreditCard.is_credit_card?(value) end |