Class: DPay::CardData
- Inherits:
-
Object
- Object
- DPay::CardData
- Defined in:
- lib/dpay/card/card_data.rb,
sig/dpay/card/card_data.rbs
Constant Summary collapse
- PAN =
/\A\d{12,19}\z/- CVV =
/\A\d{3,4}\z/- EXPIRY =
%r{\A(0[1-9]|1[0-2])/\d{2}\z}
Instance Attribute Summary collapse
-
#cvv ⇒ String
readonly
Returns the value of attribute cvv.
-
#expiry ⇒ String
readonly
Returns the value of attribute expiry.
-
#pan ⇒ String
readonly
Returns the value of attribute pan.
Instance Method Summary collapse
-
#initialize(pan, cvv, expiry) ⇒ CardData
constructor
A new instance of CardData.
- #inspect ⇒ String (also: #to_s)
Constructor Details
#initialize(pan, cvv, expiry) ⇒ CardData
Returns a new instance of CardData.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dpay/card/card_data.rb', line 11 def initialize(pan, cvv, expiry) normalized = pan.to_s.delete(" ") raise InvalidArgumentError, "Card number must be 12-19 digits" unless PAN.match?(normalized) raise InvalidArgumentError, "CVV must be 3-4 digits" unless CVV.match?(cvv.to_s) raise InvalidArgumentError, "Expiry must be in MM/YY format" unless EXPIRY.match?(expiry.to_s) @pan = normalized @cvv = cvv @expiry = expiry freeze end |
Instance Attribute Details
#cvv ⇒ String (readonly)
Returns the value of attribute cvv.
9 10 11 |
# File 'lib/dpay/card/card_data.rb', line 9 def cvv @cvv end |
#expiry ⇒ String (readonly)
Returns the value of attribute expiry.
9 10 11 |
# File 'lib/dpay/card/card_data.rb', line 9 def expiry @expiry end |
#pan ⇒ String (readonly)
Returns the value of attribute pan.
9 10 11 |
# File 'lib/dpay/card/card_data.rb', line 9 def pan @pan end |
Instance Method Details
#inspect ⇒ String Also known as: to_s
24 25 26 |
# File 'lib/dpay/card/card_data.rb', line 24 def inspect "#<DPay::CardData pan=[FILTERED] cvv=[FILTERED] expiry=[FILTERED]>" end |