credit_cards_validator 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e72e81f4b144a5808ddd50f366b27833b1a5e73dd3c25a32a3831ce1b53b1c7f
4
- data.tar.gz: 995feb1c4408d39b231446fe284dfff03d5e4099d931201fa357907d7ae52ee1
3
+ metadata.gz: f8d77e2323014cadcccd57be43780ef6890f7bb8be8226795f08682bff8f0621
4
+ data.tar.gz: 99ff88b4a9f923ca3759f7a42f6d1f792f8fb33e54f0ba481bd298ab3a52b28e
5
5
  SHA512:
6
- metadata.gz: 0ab59c116780873fb28fc30e02eb13130944363ab0bdcd42dd7e80a3282bd5d5af97c5e5069e101b72000a6b1d763e862f86c49f3e3d864c249740d42db7f422
7
- data.tar.gz: 9e09d56ca38bf03612726e0becb0136b292b3f42059b9fd3e7b2671b7a61857cced0f8311ac857cd56785f74745fc52222c0d698bc76af3b4d20fccd38c01721
6
+ metadata.gz: 2014da2c96d1f14953954b5e92fc223b9f7fc0440f6d398670764a5f4d97f6462b4d0dffd686ee9fff592fc1451c39ee3bf71d77a73d697e91e9ae36bc32cd67
7
+ data.tar.gz: '091ae0941bb697f745530ae5350a59e1b8e873cf444c5c0142caa9cef1197db02f414f5a5d54ccf99684d181118bd3b86c3d634dc2a387ec76cb3a76f6863c3d'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- credit_card_validator (0.1.0)
4
+ credit_cards_validator (0.7.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -27,7 +27,7 @@ PLATFORMS
27
27
 
28
28
  DEPENDENCIES
29
29
  bundler (>= 1.16)
30
- credit_card_validator!
30
+ credit_cards_validator!
31
31
  rake (~> 10.0)
32
32
  rspec (~> 3.0)
33
33
 
data/README.md CHANGED
@@ -1,15 +1,11 @@
1
- # CreditCardValidator
2
1
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/credit_card_validator`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
2
 
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
10
6
 
11
7
  ```ruby
12
- gem 'credit_card_validator'
8
+ gem 'credit_cards_validator'
13
9
  ```
14
10
 
15
11
  And then execute:
@@ -18,15 +14,33 @@ And then execute:
18
14
 
19
15
  Or install it yourself as:
20
16
 
21
- $ gem install credit_card_validator
17
+ $ gem install credit_cards_validator
22
18
 
23
19
  ## Usage
24
20
 
25
21
  You only need to do this:
26
22
 
27
- `ValidateCard.card_number_validate(number)`
23
+ ValidateCard.card_number_validate(number)
24
+
25
+ and then it will return true for valid credit card or false for invalid credit card. if you use this gem inside terminal, require 'credit_card_validator' instead.
26
+
27
+ if you want to get the brand name you only need to do this:
28
+
29
+ ValidateCard.brand_name(number)
30
+
31
+ and then you will get card brand name like this...
32
+
33
+ :master_card
34
+
35
+ You can use:
36
+
37
+ ValidateCard.brand_name(number).to_s.tr("_"," ").capitalize
38
+
39
+ and you will get humanized name
40
+
41
+ Current Card Brand Names:
28
42
 
29
- and then it will return true for valid credit card or false for invalid credit card.
43
+ Master Card, Visa, Diners Club, JCB, American Express, Discover
30
44
 
31
45
  ## Development
32
46
 
@@ -0,0 +1,24 @@
1
+ module CreditCardValidator
2
+ class CreditCardBrandName
3
+ CARD_BRANDS = {
4
+ master_card: /^5[1-5][0-9]{14}$|^2(?:2(?:2[1-9]|[3-9][0-9])|[3-6][0-9][0-9]|7(?:[01][0-9]|20))[0-9]{12}$/,
5
+ american_express: /^3[47][0-9]{13}$/,
6
+ visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
7
+ discover: /^65[4-9][0-9]{13}|64[4-9][0-9]{13}|6011[0-9]{12}|(622(?:12[6-9]|1[3-9][0-9]|[2-8][0-9][0-9]|9[01][0-9]|92[0-5])[0-9]{10})$/,
8
+ diners_club: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
9
+ jcb: /^(?:2131|1800|35[0-9]{3})[0-9]{11}$/
10
+ }
11
+
12
+ def self.verify_card_brand(number)
13
+ raise "Invalid Card Number" unless ValidateCard.card_number_validate(number)
14
+ CARD_BRANDS.each do |key, value|
15
+ pattern = Regexp.new(value)
16
+ if pattern.match?(number.to_s)
17
+ return key
18
+ #.to_s.tr("_"," ").capitalize
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -1,3 +1,3 @@
1
1
  module CreditCardValidator
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
@@ -1,15 +1,15 @@
1
1
  require "credit_card_validator/version"
2
2
 
3
3
  class ValidateCard
4
-
4
+
5
5
  def self.card_number_validate(card_number)
6
6
  card_number = card_number.to_s.split('')
7
7
  card_number.each_with_index.map do |value, index|
8
8
  card_number[index] = value.to_i #Change to integer
9
9
  end
10
10
  card_digit = card_number[-1]
11
- card_number.pop() # Remove digit from calculation
12
- card_number = card_number.reverse()
11
+ card_number.pop() # Remove digit from calculation to start counting (index 1 instead 0)
12
+ card_number = card_number.reverse()
13
13
  card_number.each_with_index.map do |value, index|
14
14
  if index.even?
15
15
  value = value * 2
@@ -27,7 +27,13 @@ class ValidateCard
27
27
  end
28
28
  return false
29
29
  end
30
+
31
+ def self.brand_name(number)
32
+ CreditCardValidator::CreditCardBrandName.verify_card_brand(number)
33
+ end
30
34
  end
31
35
 
36
+ require 'credit_card_validator/credit_card_brand_name'
37
+
32
38
 
33
39
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: credit_cards_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - bin/setup
73
73
  - credit_cards_validator.gemspec
74
74
  - lib/credit_card_validator.rb
75
+ - lib/credit_card_validator/credit_card_brand_name.rb
75
76
  - lib/credit_card_validator/version.rb
76
77
  homepage: https://github.com/MatheusHH/credit_card_validator
77
78
  licenses:
@@ -93,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
94
  - !ruby/object:Gem::Version
94
95
  version: '0'
95
96
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.7.7
97
+ rubygems_version: 3.3.3
98
98
  signing_key:
99
99
  specification_version: 4
100
100
  summary: A Gem to validate credit cards.