credit_debit_card_number_validator 16.09.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2fe4b1769f2bdf3e475d7488dc2c3754e6a7ed57
4
+ data.tar.gz: f4f531805de32ab1fdf42401b02f8c3139519e67
5
+ SHA512:
6
+ metadata.gz: 94550e6ffaffba5a1c79232a840131ffb2f59ad461db8427a4f2da0c42e08f93d684fd309602f9176cee068cb249a3dff1a4f88e7020a158f9e7a2862fd82b11
7
+ data.tar.gz: ffa1ec73b5ec3c653ecde3d429cd7dea68c7fd59fd50851998def3536fe8e4af97aef3568cc5e4f4416749ce7b3c04dd06b07e0713672b8541024c659be058c6
@@ -0,0 +1,95 @@
1
+ # Suppoerted Companies:
2
+ # amex | American Express | 15 | Luhn | 34, 37
3
+
4
+ # bc4 | Bankcard | 16 | Luhn | 5610
5
+ # bc6 | Bankcard | 16 | Luhn | 560221 - 560225
6
+
7
+ # cebi | CARDGUARD EAD BG ILS | 16 | Luhn | 5392
8
+
9
+ # cup | China UnionPay | 16, 17, 18, 19 | Unk | 622, 624 - 626, 628
10
+
11
+ # dn | Dancord | 16 | Luhn | 5019
12
+
13
+ # dccb | Diners Club Carte Blanche | 14 | Luhn | 300 - 305
14
+ # dcer | Diners Club enRoute | 15 | No V | 2014, 2149
15
+ # dcint2 | Diners Club International | 14 | Luhn | 36, 38, 39
16
+ # dcint3 | Diners Club International | 14 | Luhn | 309
17
+
18
+ # disc2 | Discover Card | 16 | Luhn | 65
19
+ # disc3 | Discover Card | 16 | Luhn | 644 - 649
20
+ # disc4 | Discover Card | 16 | Luhn | 6011
21
+ # disc6 | Discover Card | 16 | Luhn | 622126 - 622925
22
+
23
+ # hc | Hipercard | 19 | Luhn | 348
24
+
25
+ # ipi | InstaPayment | 16 | Luhn | 637 - 639
26
+
27
+ # ipr | InterPayment | 16, 17, 18, 19 | Luhn | 636
28
+
29
+ # jcb3 | JCB | 15, 16 | Luhn | 353 - 358
30
+ # jcb4 | JCB | 15, 16 | Luhn | 3528, 3589, 3088, 3112, 3337, 3158, 3096, 1000, 2131
31
+ # jcb6 | JCB | 15, 16 | Luhn | 357266
32
+
33
+ # laser | Laser | 16, 17, 18, 19 | Luhn | 6304, 6706, 6771, 6709
34
+
35
+ # maes2 | Maestro | 12 ........ 19 | Luhn | 56 - 59
36
+ # maes3 | Maestro | 12 ........ 19 | Luhn | 502 - 509, 602 - 605, 671 - 675, 500, 621, 627, 629, 677, 679
37
+ # maes4 | Maestro | 12 ........ 19 | Luhn | 5010 - 5018, 6010, 6012 - 6019, 6760 - 6766, 6768 - 6771, 6060, 6304, 6390
38
+
39
+ # mc2 | Master Card | 16 | Luhn | 51 - 55, 23 - 26
40
+ # mc3 | Master Card | 16 | Luhn | 223 - 229, 271
41
+ # mc4 | Master Card | 16 | Luhn | 2221 - 2229, 2720
42
+
43
+ # rupay3 | RuPay | 16 | Unk | 607, 608
44
+ # rupay4 | RuPay | 16 | Unk | 6061 - 6069
45
+
46
+ # solo | Solo | 16, 18, 19 | Luhn | 6334, 6767
47
+
48
+ # swch4 | Switch | 16, 18, 19 | Luhn | 4903, 4905, 4911, 4936, 6333, 6759
49
+ # swch6 | Switch | 16, 18, 19 | Luhn | 633312, 633110, 633304, 633303, 633301, 633300
50
+
51
+ # uatp | UATP | 15 | Luhn | 1
52
+
53
+ # verve | Verve | 16, 19 | Luhn | 506099 - 506198, 650002 - 650027
54
+
55
+ # visae4 | Visa Electron | 13, 16 | Luhn | 4026, 4508, 4844, 4913, 4917
56
+ # visae6 | Visa Electron | 13, 16 | Luhn | 417500
57
+
58
+ # visa | Visa | 13, 16 | Luhn | 4
59
+
60
+ # voy | Voyager | 15 | Luhn | 8699
61
+
62
+ # Supported companies with other brands:
63
+ # dcuc | Diners Club US and Canada | 16 | Luhn | 54, 55 | Master Card
64
+
65
+ # Resources:
66
+ # http://blog.groundlabs.com/cardholder-data-discovery-anatomy-of-a-credit-card-bin-ranges-luhn-checks
67
+ # http://en.wikipedia.org/wiki/Payment_card_number
68
+ # http://www.iinbase.com
69
+ # http://www.getcreditcardnumbers.com
70
+ # http://planetcalc.com/2464/
71
+
72
+ # require classes files
73
+ require 'validator'
74
+ require 'information'
75
+
76
+ # CreditDebitCardNumberValidator module
77
+ # main module containe gem classes
78
+ # use this module to deal with gem classes,
79
+ # create objects and work with class methods
80
+ # to validate your data
81
+ module CreditDebitCardNumberValidator
82
+
83
+ # Validator class
84
+ # validate and gathering information about card number
85
+ # 11 methods
86
+ # it is included using require 'validator'
87
+ class Validator
88
+ end
89
+
90
+ # Information class
91
+ # store all card number information
92
+ # it is included using require 'information'
93
+ class Information
94
+ end
95
+ end
@@ -0,0 +1,34 @@
1
+ # CreditDebitCardNumberValidator module
2
+ # main module containe gem classes
3
+ # use this module to deal with gem classes,
4
+ # create objects and work with class methods
5
+ # to validate your data
6
+ module CreditDebitCardNumberValidator
7
+
8
+ # Information class
9
+ # store all card number information to return it later
10
+ class Information
11
+
12
+ # make all class variables accessible
13
+ attr_accessor :card_number, :is_valid, :mod_10_result, :iin, :brand, :check_digit, :length
14
+
15
+ # initializer to initialize all class variables
16
+ # class variables:
17
+ # @card_number -> store card number
18
+ # @is_valid -> store luhn algorithm result
19
+ # @mod_10_result -> store mod 10 result from luhn algorithm
20
+ # @iin -> store card number IIN Range
21
+ # @brand -> store card brand
22
+ # @check_digit -> store the next check digit of card number
23
+ # @length -> store card number length
24
+ def initialize
25
+ @card_number = 0
26
+ @is_valid = false
27
+ @mod_10_result = 0
28
+ @iin = 0
29
+ @brand = ''
30
+ @check_digit = ''
31
+ @length = 0
32
+ end
33
+ end
34
+ end
data/lib/tests.rb ADDED
@@ -0,0 +1,51 @@
1
+ # require gem
2
+ require 'credit_debit_card_number_validator'
3
+
4
+ # test almost brand supported by gem
5
+ p CreditDebitCardNumberValidator::Validator.all_information_about('348998173777802') # American Express
6
+ puts
7
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6264185212922132067') # China UnionPay
8
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6288997715452584') # China UnionPay
9
+ puts
10
+ p CreditDebitCardNumberValidator::Validator.all_information_about('5019717010103742') # Dancord
11
+ puts
12
+ p CreditDebitCardNumberValidator::Validator.all_information_about('30350713037359') # Diners Club Carte Blanche
13
+ p CreditDebitCardNumberValidator::Validator.all_information_about('214914222364956') # Diners Club enRoute
14
+ p CreditDebitCardNumberValidator::Validator.all_information_about('36014781278733') # Diners Club International
15
+ puts
16
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6011622563605042') # Discover
17
+ puts
18
+ p CreditDebitCardNumberValidator::Validator.all_information_about('3841005899088180330') # Hipercard
19
+ puts
20
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6380654534552139') # InstaPayment
21
+ puts
22
+ p CreditDebitCardNumberValidator::Validator.all_information_about('3572660000000000006') # JCB
23
+ p CreditDebitCardNumberValidator::Validator.all_information_about('3337910604152361') # JCB
24
+ p CreditDebitCardNumberValidator::Validator.all_information_about('180001638277392') # JCB
25
+ puts
26
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6706020938769058234') # Laser
27
+ p CreditDebitCardNumberValidator::Validator.all_information_about('677180246316181805') # Laser
28
+ p CreditDebitCardNumberValidator::Validator.all_information_about('63049092800799270') # Laser
29
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6304445859171404') # Laser
30
+ puts
31
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6799990100000000019') # Maestro
32
+ p CreditDebitCardNumberValidator::Validator.all_information_about('639002000000000003') # Maestro
33
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6762470273176461') # Maestro
34
+ p CreditDebitCardNumberValidator::Validator.all_information_about('50339619890917') # Maestro
35
+ puts
36
+ p CreditDebitCardNumberValidator::Validator.all_information_about('5501943861489569') # Mastercard
37
+ puts
38
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6076600006199992') # RuPay
39
+ puts
40
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6767622222222222222') # Solo
41
+ p CreditDebitCardNumberValidator::Validator.all_information_about('633473060000000000') # Solo
42
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6334900000000005') # Solo
43
+ puts
44
+ p CreditDebitCardNumberValidator::Validator.all_information_about('6331101999990016') # Switch
45
+ puts
46
+ p CreditDebitCardNumberValidator::Validator.all_information_about('4929334156772439') # Visa
47
+ p CreditDebitCardNumberValidator::Validator.all_information_about('4556462552594') # Visa
48
+ puts
49
+ p CreditDebitCardNumberValidator::Validator.all_information_about('4913727680252737') # Visa Electron
50
+ puts
51
+ p CreditDebitCardNumberValidator::Validator.all_information_about('869973319748289') # Voyager
data/lib/validator.rb ADDED
@@ -0,0 +1,306 @@
1
+ # CreditDebitCardNumberValidator module
2
+ # main module containe gem classes
3
+ # use this module to deal with gem classes,
4
+ # create objects and work with class methods
5
+ # to validate your data
6
+ module CreditDebitCardNumberValidator
7
+
8
+ # Validator class
9
+ # validate and gathering information about card number
10
+ # 11 methods
11
+ class Validator
12
+
13
+ # class method > check
14
+ # check card_number variable is contain digits on it or not
15
+ # if there is not digits the method raise ArgumentError
16
+ # with message 'no card number specified'
17
+ def self.check card_number
18
+ raise ArgumentError, "no card number specified" if card_number.to_i == 0
19
+ end
20
+
21
+ # class method > all_info
22
+ # get every information about card number and
23
+ # return them in object of type Information class
24
+ # return example: #<CreditDebitCardNumberValidator::Information:0x2eb4b90 @card_number="4929334156772439", @is_valid=true, @mod_10_result=0, @iin=4, @brand="Visa", @check_digit="9", @length=16>
25
+ def self.all_information_about card_number
26
+
27
+ # check card_number variable
28
+ check card_number
29
+
30
+ # create new object of type Information class
31
+ # to store information in it
32
+ info = Information.new
33
+
34
+ # validate and gathering information and store them in info object
35
+ info.card_number = card_number
36
+ info.is_valid, info.mod_10_result = validate card_number
37
+ info.iin, info.brand = determine_iin_and_brand card_number
38
+ info.check_digit = next_check_digit card_number
39
+ info.length = number_length card_number
40
+
41
+ # return info object that contain information about the card number
42
+ info
43
+ end
44
+
45
+ # class method > validate
46
+ # validate card number using luhn algorithm and return array contain
47
+ # true if the number pass the test or false otherwise with mod 10 result
48
+ # return example: [true, 0]
49
+ # return example: {'luhn test' => (true), 'mod 10 result' => 0}
50
+ def self.validate card_number
51
+
52
+ # check card_number variable
53
+ check card_number
54
+
55
+ # initialize variable to do the luhn test
56
+ total = 0
57
+
58
+ # apply the test
59
+ if card_number.size.even?
60
+ # if card number length is even
61
+ card_number.split('').each_with_index { |e, i| i.even? ? total += ((e.to_i * 2) > 9 ? (e.to_i * 2) - 9 : (e.to_i * 2)) : total += e.to_i }
62
+ else
63
+ # if card number length is odd
64
+ card_number.split('').each_with_index { |e, i| i.odd? ? total += ((e.to_i * 2) > 9 ? (e.to_i * 2) - 9 : (e.to_i * 2)) : total += e.to_i }
65
+ end
66
+
67
+ # return the result
68
+ [total % 10 == 0, total % 10]
69
+ end
70
+
71
+ # class method > luhn_test
72
+ # validate card number using luhn algorithm and return
73
+ # true if the number pass the test or false otherwise
74
+ # return example: true
75
+ def self.luhn_test card_number
76
+
77
+ # check card_number variable
78
+ check card_number
79
+
80
+ (validate card_number)[0]
81
+ end
82
+
83
+ # class method > mod_10_result
84
+ # validate card number using luhn algorithm and return mod 10 result
85
+ # return example: 0
86
+ def self.mod_10_result card_number
87
+
88
+ # check card_number variable
89
+ check card_number
90
+
91
+ (validate card_number)[1]
92
+ end
93
+
94
+ # class method > determine_iin_and_brand
95
+ # determine card brand using IIN Ranges and return array contain
96
+ # the IIN of the card number and the brand name
97
+ # return example: [37, 'American Express']
98
+ # return example: {'IIN' => 37, 'Brand Name' => 'American Express'}
99
+ def self.determine_iin_and_brand card_number
100
+
101
+ # check card_number variable
102
+ check card_number
103
+
104
+ # calculate card number length
105
+ length = card_number.size
106
+
107
+ # preparation IIN Ranges from card number
108
+ iin1 = card_number[0]
109
+ iin2 = card_number[0..1]
110
+ iin3 = card_number[0..2]
111
+ iin4 = card_number[0..3]
112
+ iin6 = card_number[0..5]
113
+
114
+ # test all IIN Ranges of supported brands
115
+ if (['34', '37'].include? (iin2)) && length == 15
116
+ [iin2.to_i, 'American Express']
117
+ # {'IIN' => iin2.to_i, 'Company Name' => 'American Express'}
118
+ elsif iin4 == '5610' && length == 16
119
+ [iin4.to_i, 'Bankcard']
120
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Bankcard'}
121
+ elsif (('560221'..'560225').include? (iin6)) && length == 16
122
+ [iin6.to_i, 'Bankcard']
123
+ # {'IIN' => iin6.to_i, 'Company Name' => 'Bankcard'}
124
+ elsif iin4 == '5392' && length == 16
125
+ [iin4.to_i, 'CARDGUARD EAD BG ILS']
126
+ # {'IIN' => iin4.to_i, 'Company Name' => 'CARDGUARD EAD BG ILS'}
127
+ elsif (['622', '624', '625', '626', '628'].include? (iin3)) && (length >= 16 && length <= 19)
128
+ [iin3.to_i, 'China UnionPay']
129
+ # {'IIN' => iin3.to_i, 'Company Name' => 'China UnionPay'}
130
+ elsif iin4 == '5019' && length == 16
131
+ [iin4.to_i, 'Dankort']
132
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Dankort'}
133
+ elsif (('301'..'305').include? (iin3)) && length == 14
134
+ [iin3.to_i, 'Diners Club Carte Blanche']
135
+ # {'IIN' => iin3.to_i, 'Company Name' => 'Diners Club Carte Blanche'}
136
+ elsif (['2014', '2149'].include? (iin4)) && length == 15
137
+ [iin4.to_i, 'Diners Club Carte enRoute']
138
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Diners Club Carte enRoute'}
139
+ elsif (['36', '38', '39'].include? (iin2)) && length == 14
140
+ [iin2.to_i, 'Diners Club International']
141
+ # {'IIN' => iin2.to_i, 'Company Name' => 'Diners Club International'}
142
+ elsif iin3 == '309' && length == 14
143
+ [iin3.to_i, 'Diners Club International']
144
+ # {'IIN' => iin3.to_i, 'Company Name' => 'Diners Club International'}
145
+ elsif iin2 == '65' && length == 16
146
+ [iin2.to_i, 'Discover Card']
147
+ # {'IIN' => iin2.to_i, 'Company Name' => 'Discover Card'}
148
+ elsif (('644'..'649').include? (iin3)) && length == 16
149
+ [iin3.to_i, 'Discover Card']
150
+ # {'IIN' => iin3.to_i, 'Company Name' => 'Discover Card'}
151
+ elsif iin4 == '6011' && length == 16
152
+ [iin4.to_i, 'Discover Card']
153
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Discover Card'}
154
+ elsif (('622126'..'622925').include? (iin6)) && length == 16
155
+ [iin6.to_i, 'Discover Card']
156
+ # {'IIN' => iin6.to_i, 'Company Name' => 'Discover Card'}
157
+ elsif iin3 == '384' && length == 19
158
+ [iin3.to_i, 'Hipercard']
159
+ # {'IIN' => iin3.to_i, 'Company Name' => 'Hipercard'}
160
+ elsif (('637'..'639').include? (iin3)) && length == 16
161
+ [iin3.to_i, 'InstaPayment']
162
+ # {'IIN' => iin3.to_i, 'Company Name' => 'InstaPayment'}
163
+ elsif iin3 == '636' && (length >= 16 && length <= 19)
164
+ [iin3.to_i, 'InterPayment']
165
+ # {'IIN' => iin3.to_i, 'Company Name' => 'InterPayment'}
166
+ elsif (('353'..'358').include? (iin3)) && (length == 15 || length == 16)
167
+ [iin3.to_i, 'JCB']
168
+ # {'IIN' => iin3.to_i, 'Company Name' => 'JCB'}
169
+ elsif ((('3528'..'3589').include? (iin4)) || (['3088', '3096', '3112', '3158', '3337'].include? (iin4))) && (length == 15 || length == 16)
170
+ [iin4.to_i, 'JCB']
171
+ # {'IIN' => iin4.to_i, 'Company Name' => 'JCB'}
172
+ elsif (['1800', '2131'].include? (iin4)) && length == 15
173
+ [iin4.to_i, 'JCB']
174
+ # {'IIN' => iin4.to_i, 'Company Name' => 'JCB'}
175
+ elsif iin6 == '357266' && length == 19
176
+ [iin6.to_i, 'JCB']
177
+ # {'IIN' => iin6.to_i, 'Company Name' => 'JCB'}
178
+ elsif (['6304', '6706', '6771', '6709'].include? (iin4)) && (length >= 16 && length <= 19)
179
+ [iin4.to_i, 'Laser']
180
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Laser'}
181
+ elsif (('56'..'59').include? (iin2)) && (length >= 12 && length <= 19)
182
+ [iin2.to_i, 'Maestro']
183
+ # {'IIN' => iin2.to_i, 'Company Name' => 'Maestro'}
184
+ elsif ((('502'..'509').include? (iin3)) || (('602'..'605').include? (iin3)) || (('671'..'675').include? (iin3)) || (['500', '621', '627', '629', '677', '679'].include? (iin3))) && (length >= 12 && length <= 19)
185
+ [iin3.to_i, 'Maestro']
186
+ # {'IIN' => iin3.to_i, 'Company Name' => 'Maestro'}
187
+ elsif ((('5010'..'5018').include? (iin4)) || (('6012'..'6019').include? (iin4)) || (('6760'..'6766').include? (iin4)) || (('6768'..'6771').include? (iin4)) || (['6060', '6304', '6390', '6010'].include? (iin4))) && (length >= 12 && length <= 19)
188
+ [iin4.to_i, 'Maestro']
189
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Maestro'}
190
+ elsif ((('51'..'55').include? (iin2)) || (('23'..'26').include? (iin2))) && length == 16
191
+ [iin2.to_i, 'Master Card']
192
+ # {'IIN' => iin2.to_i, 'Company Name' => 'Master Card'}
193
+ elsif ((('223'..'229').include? (iin3)) || iin3 == '271') && length == 16
194
+ [iin3.to_i, 'Master Card']
195
+ # {'IIN' => iin3.to_i, 'Company Name' => 'Master Card'}
196
+ elsif ((('2221'..'2229').include? (iin4)) || iin4 == '2720') && length == 16
197
+ [iin4.to_i, 'Master Card']
198
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Master Card'}
199
+ elsif (['607', '608'].include? (iin3)) && length == 16
200
+ [iin3.to_i, 'RuPay']
201
+ # {'IIN' => iin3.to_i, 'Company Name' => 'RuPay'}
202
+ elsif (('6061'..'6069').include? (iin4)) && length == 16
203
+ [iin4.to_i, 'RuPay']
204
+ # {'IIN' => iin4.to_i, 'Company Name' => 'RuPay'}
205
+ elsif (['6334', '6767'].include? (iin4)) && (length == 16 || length == 18 || length == 19)
206
+ [iin4.to_i, 'Solo']
207
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Solo'}
208
+ elsif (['4903', '4905', '4911', '4936', '6333', '6759'].include? (iin4)) && (length == 16 || length == 18 || length == 19)
209
+ [iin4.to_i, 'Switch']
210
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Switch'}
211
+ elsif (['633312', '633110', '633304', '633303', '633301', '633300'].include? (iin6)) && (length == 16 || length == 18 || length == 19)
212
+ [iin6.to_i, 'Switch']
213
+ # {'IIN' => iin6.to_i, 'Company Name' => 'Switch'}
214
+ elsif iin1 == '1' && length == 15
215
+ [iin1.to_i, 'UATP']
216
+ # {'IIN' => iin1.to_i, 'Company Name' => 'UATP'}
217
+ elsif (('506099'..'506198').include? (iin6)) || (('650002'..'650027').include? (iin6)) && (length == 16 || length == 19)
218
+ [iin6.to_i, 'Verve']
219
+ # {'IIN' => iin6.to_i, 'Company Name' => 'Verve'}
220
+ elsif (['4026', '4508', '4844', '4913', '4917'].include? (iin4)) && (length == 13 || length == 16)
221
+ [iin4.to_i, 'Visa Electron']
222
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Visa Electron'}
223
+ elsif iin6 == '417500' && (length == 13 || length == 16)
224
+ [iin6.to_i, 'Visa Electron']
225
+ # {'IIN' => iin6.to_i, 'Company Name' => 'Visa Electron'}
226
+ elsif iin1 == '4' && (length == 13 || length == 16)
227
+ [iin1.to_i, 'Visa']
228
+ # {'IIN' => iin1.to_i, 'Company Name' => 'Visa'}
229
+ elsif iin4 == '8699' && length == 15
230
+ [iin4.to_i, 'Voyager']
231
+ # {'IIN' => iin4.to_i, 'Company Name' => 'Voyager'}
232
+ else
233
+ # return 0 as IIN Range and Unknown as brand name if card number is not determined
234
+ [0, 'Unknown']
235
+ # {'IIN' => 0, 'Brand Name' => 'Unknown'}
236
+ end
237
+ end
238
+
239
+ # class method > determine_iin
240
+ # determine card IIN Ranges and return it
241
+ # return example: 37
242
+ def self.determine_iin card_number
243
+
244
+ # check card_number variable
245
+ check card_number
246
+
247
+ (determine_iin_and_company card_number)[0]
248
+ end
249
+
250
+ # class method > determine_brand
251
+ # determine card brand using IIN Ranges and return it
252
+ # return example: 'Visa'
253
+ def self.determine_brand card_number
254
+
255
+ # check card_number variable
256
+ check card_number
257
+
258
+ (determine_iin_and_brand card_number)[1]
259
+ end
260
+
261
+ # class method > next_check_digit
262
+ # calculate the next check digit of card number and return it
263
+ # return example: '3'
264
+ def self.next_check_digit card_number
265
+
266
+ # check card_number variable
267
+ check card_number
268
+
269
+ # calculate mod 10 result by applying luhn algorithm
270
+ tmp = (validate (card_number + '0'))[1]
271
+
272
+ # if mod 10 result equal to 0 return 0 else subtract the result from 10 and return
273
+ tmp == 0 ? '0' : (10 - tmp).to_s
274
+ end
275
+
276
+ # class method > next_check_digits
277
+ # calculate the next check digits of card number and return them
278
+ # return example: '91834'
279
+ def self.next_check_digits card_number, number
280
+
281
+ # check card_number variable
282
+ check card_number
283
+
284
+ # initialize variable to return it
285
+ tmp = ''
286
+
287
+ # add next check digits
288
+ number.times { tmp += (card_number += next_check_digit card_number)[-1] }
289
+
290
+ # return next check digits
291
+ tmp
292
+ end
293
+
294
+ # class method > number_length
295
+ # calculate and return card number length
296
+ # return example: 16
297
+ def self.number_length card_number
298
+
299
+ # check card_number variable
300
+ check card_number
301
+
302
+ # return card number length
303
+ card_number.size
304
+ end
305
+ end
306
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credit_debit_card_number_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 16.09.4
5
+ platform: ruby
6
+ authors:
7
+ - Ali Osm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple way to validate credit/debit card number uring ruby
14
+ email: aliosm1997@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/credit_debit_card_number_validator.rb
20
+ - lib/validator.rb
21
+ - lib/information.rb
22
+ - lib/tests.rb
23
+ homepage: https://github.com/AliOsm/credit_debit_card_number_validator
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.14.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Validator
47
+ test_files: []