credit_card_validations 6.1.0 → 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b8d3e090e222ece5a4532b931d8bfedf9a4ac73e2c924e09c6c2d465364c3ca
4
- data.tar.gz: 10f9892d010c271806dcbce9c26178a3318873ae3b925c719e6e496a529bc89b
3
+ metadata.gz: 80528d2245ce569ed3b865c186f272d37581606a90ca679e391da8abfd3f003b
4
+ data.tar.gz: 85100246c15156a33e7c491988edcfddc171f26e63dc38dd4783636becb5912a
5
5
  SHA512:
6
- metadata.gz: e4bc9ea274ed6cf155c6185b36bca6a99c28fcf7f73634b4679c0ffe2103b953fad46f8595dc82a76ba559358554d968faccdfe511c4666395c718e4296abfe8
7
- data.tar.gz: 9c7dd57ab21943def16202b67a50494713cfc46c30c6b2cf6f11208d81c9ee721edf48e3ada864a7abdb081c2f14990ec905504b4db9920b209bdb3fdbb665a7
6
+ metadata.gz: 276527c57560abaad1216c80bc76e0e57861337ded7451902e5c872800eaaf7deb00b89d1426adbea3100702ff100179a3a16232728bf541242e3002303c3ffd
7
+ data.tar.gz: b3ae52f16663e2acf0a6133f170c2f3d73e13aaa1814f7fc4e165d5d93f6282ef4751e8e79f43d174d1ff6f5708c5a3da28aa82180917eecef85df86b09c7111
@@ -15,6 +15,7 @@ jobs:
15
15
  - '3.0'
16
16
  - 3.1
17
17
  - 3.2
18
+ - 3.3
18
19
  rails:
19
20
  - '6.1.5'
20
21
  - '7.0.2.3'
data/Changelog.md CHANGED
@@ -1,3 +1,10 @@
1
+ # 6.2.0
2
+ * support ruby 3.3
3
+ * more accurate brand matching using matched prefix length
4
+
5
+ # 6.1.0
6
+ * support rails 7.1
7
+
1
8
  # 6.0.0
2
9
  * changes to discover branch
3
10
  * allows to configure usage of own yaml brands file
@@ -28,8 +28,14 @@ module CreditCardValidations
28
28
  def valid_number?(*keys)
29
29
  selected_brands = keys.blank? ? self.brands : resolve_keys(*keys)
30
30
  if selected_brands.any?
31
+ matched_brands = []
31
32
  selected_brands.each do |key, brand|
32
- return key if matches_brand?(brand)
33
+ match_data = matches_brand?(brand)
34
+ matched_brands << {brand: key, matched_prefix_length: match_data.to_s.length} if match_data
35
+ end
36
+
37
+ if matched_brands.present?
38
+ return matched_brands.sort{|a, b| a[:matched_prefix_length] <=> b[:matched_prefix_length]}.last[:brand]
33
39
  end
34
40
  end
35
41
  nil
@@ -64,8 +70,8 @@ module CreditCardValidations
64
70
  rules.each do |rule|
65
71
  if (options[:skip_luhn] || valid_luhn?) &&
66
72
  rule[:length].include?(number.length) &&
67
- number.match(rule[:regexp])
68
- return true
73
+ match_data = number.match(rule[:regexp])
74
+ return match_data
69
75
  end
70
76
  end
71
77
  false
@@ -1,3 +1,3 @@
1
1
  module CreditCardValidations
2
- VERSION = '6.1.0'
2
+ VERSION = '6.2.0'
3
3
  end
@@ -170,6 +170,28 @@ describe CreditCardValidations do
170
170
  end
171
171
  end
172
172
  end
173
+
174
+ describe 'Add kortimilli rule' do
175
+ let(:kortimilli_number) { '505827028341713' }
176
+
177
+ it 'before invoke add_brand credit card behaves like maestro' do
178
+ expect(detector(kortimilli_number).valid?(:maestro)).must_equal true
179
+ expect(detector(kortimilli_number).maestro?).must_equal true
180
+ expect(detector(kortimilli_number).brand).must_equal :maestro
181
+ end
182
+
183
+ describe 'after adding wider prefix for kortimilli' do
184
+ before do
185
+ CreditCardValidations::Detector.add_brand(:kortimilli, length: 15, prefixes: '505827028')
186
+ end
187
+
188
+ it 'should validate number as kortimilli' do
189
+ expect(detector(kortimilli_number).valid?(:kortimilli)).must_equal true
190
+ expect(detector(kortimilli_number).kortimilli?).must_equal true
191
+ expect(detector(kortimilli_number).brand).must_equal :kortimilli
192
+ end
193
+ end
194
+ end
173
195
  end
174
196
 
175
197
  describe 'plugins' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_card_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-30 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.3.7
170
+ rubygems_version: 3.4.22
171
171
  signing_key:
172
172
  specification_version: 4
173
173
  summary: gem should be used for credit card numbers validation, card brands detections,