credit_card_validations 1.2.0 → 1.3.0

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.
data/README.md CHANGED
@@ -51,11 +51,13 @@ Examples using string monkey patch
51
51
 
52
52
  Examples using CreditCardValidations::Detector class
53
53
 
54
- number = "41111111111111111"
55
- CreditCardValidations::Detector.new(number).brand #:visa
56
- CreditCardValidations::Detector.new(number).visa? #true
57
- CreditCardValidations::Detector.new(number).valid?(:mastercard,:maestro) #false
58
- CreditCardValidations::Detector.new(number).valid?(:visa, :mastercard) #true
54
+ number = "4111111111111111"
55
+ detector = CreditCardValidations::Detector.new(number)
56
+ detector.brand #:visa
57
+ detector.visa? #true
58
+ detector.valid?(:mastercard,:maestro) #false
59
+ detector.valid?(:visa, :mastercard) #true
60
+ detector.issuer_category #"Banking and financial"
59
61
 
60
62
  Also You can add your own rules to detect other credit card brands/types
61
63
  passing name,length(integer/array of integers) and prefix(string/array of strings)
@@ -10,4 +10,5 @@ module CreditCardValidations
10
10
  autoload :Luhn, 'credit_card_validations/luhn'
11
11
  autoload :CardRules , 'credit_card_validations/card_rules'
12
12
  autoload :Detector , 'credit_card_validations/detector'
13
+ autoload :Mmi, 'credit_card_validations/mmi'
13
14
  end
@@ -1,5 +1,8 @@
1
1
  module CreditCardValidations
2
2
  class Detector
3
+
4
+ include Mmi
5
+
3
6
  class_attribute :rules
4
7
  self.rules = {}
5
8
 
@@ -0,0 +1,36 @@
1
+ #Major Industry Identifier (MII)
2
+ #
3
+ #The first digit of a credit card number is the Major Industry Identifier (MII), which represents the category of entity which issued the card. MII digits represent the following issuer categories:
4
+ #0 – ISO/TC 68 and other future industry assignments
5
+ #1 – Airlines
6
+ #2 – Airlines and other future industry assignments
7
+ #3 – Travel and entertainment and banking/financial
8
+ #4 – Banking and financial
9
+ #5 – Banking and financial
10
+ #6 – Merchandising and banking/financial
11
+ #7 – Petroleum and other future industry assignments
12
+ #8 – Healthcare, telecommunications and other future industry assignments
13
+ #9 – National assignment
14
+ #For example, American Express, Diner's Club, Carte Blanche, and JCB are in the travel and entertainment category; VISA, MasterCard, and Discover are in the banking and financial category (Discover being in the Merchandising and banking/financial category); and Sun Oil and Exxon are in the petroleum category.
15
+
16
+
17
+ module CreditCardValidations::Mmi
18
+
19
+ ISSUER_CATEGORIES = {
20
+ '0' =>'ISO/TC 68 nd other industry assignments',
21
+ '1' => 'Airlines',
22
+ '2' => 'Airlines and other industry assignments',
23
+ '3' => 'Travel and entertainment and banking/financial',
24
+ '4' => 'Banking and financial',
25
+ '5' => 'Banking and financial',
26
+ '6' => 'Merchandising and banking/financial',
27
+ '7' => 'Petroleum and other industry assignments',
28
+ '8' => 'Healthcare, telecommunications and other industry assignments',
29
+ '9' => 'National assignment'
30
+
31
+ }
32
+
33
+ def issuer_category
34
+ ISSUER_CATEGORIES[@number.to_s[0]]
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module CreditCardValidations
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -121,6 +121,10 @@ class CreditCardValidationsTest < Test::Unit::TestCase
121
121
  assert d.valid?(:visa, :unionpay)
122
122
  end
123
123
 
124
+ def test_mmi
125
+ d = detector(@test_numbers[:visa])
126
+ assert_equal d.issuer_category, CreditCardValidations::Mmi::ISSUER_CATEGORIES[@test_numbers[:visa][0]]
127
+ end
124
128
 
125
129
  protected
126
130
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_card_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70292463116540 !ruby/object:Gem::Requirement
16
+ requirement: &70144768852760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '4.1'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *70292463116540
27
+ version_requirements: *70144768852760
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activesupport
30
- requirement: &70292463129120 !ruby/object:Gem::Requirement
30
+ requirement: &70144768865980 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: '4.1'
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *70292463129120
41
+ version_requirements: *70144768865980
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: test-unit
44
- requirement: &70292467198680 !ruby/object:Gem::Requirement
44
+ requirement: &70144768862620 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ! '>='
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: '0'
50
50
  type: :development
51
51
  prerelease: false
52
- version_requirements: *70292467198680
52
+ version_requirements: *70144768862620
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: mocha
55
- requirement: &70292467197900 !ruby/object:Gem::Requirement
55
+ requirement: &70144768859260 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -60,10 +60,10 @@ dependencies:
60
60
  version: '0'
61
61
  type: :development
62
62
  prerelease: false
63
- version_requirements: *70292467197900
63
+ version_requirements: *70144768859260
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: rake
66
- requirement: &70292467197180 !ruby/object:Gem::Requirement
66
+ requirement: &70144768880480 !ruby/object:Gem::Requirement
67
67
  none: false
68
68
  requirements:
69
69
  - - ! '>='
@@ -71,7 +71,7 @@ dependencies:
71
71
  version: '0'
72
72
  type: :development
73
73
  prerelease: false
74
- version_requirements: *70292467197180
74
+ version_requirements: *70144768880480
75
75
  description: A ruby gem for validating credit card numbers (a port of ZF2 Zend\Validator\CreditCard)
76
76
  email:
77
77
  - fedoronchuk@gmail.com
@@ -90,6 +90,7 @@ files:
90
90
  - lib/credit_card_validations/card_rules.rb
91
91
  - lib/credit_card_validations/detector.rb
92
92
  - lib/credit_card_validations/luhn.rb
93
+ - lib/credit_card_validations/mmi.rb
93
94
  - lib/credit_card_validations/string.rb
94
95
  - lib/credit_card_validations/version.rb
95
96
  - test/credit_card_validations_test.rb