forked from jaymist/flybuys_card_validation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard.rb
More file actions
39 lines (32 loc) · 900 Bytes
/
card.rb
File metadata and controls
39 lines (32 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Represents unknown card #s, potentially not FlyBuys.
# This is important incase a POS client messes up integration,
# maybe they send Visa # instead of flybuys (which would be v bad!!)
# and the only way of linking to their account is through that record
class Card
attr_reader :card_number
def initialize(card_number)
@card_number = card_number
end
def valid?
# Only support strings - there's too much risk of
# clients or us dropping leading 0's for ints
# Would be risky trying to cast
return false unless processable?
# Matches on all generic cards, including Visa
formatted_number.match(/^\d{16}\d?$/)
end
def formatted_number
return card_number.to_s unless processable?
card_number.gsub /[- ,\.]/, ''
end
def type
:unknown
end
def matched?
true
end
private
def processable?
card_number.class == String
end
end