credy 0.2.0 → 0.2.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 +4 -4
- data/.travis.yml +1 -0
- data/Gemfile.lock +22 -14
- data/LICENSE +21 -0
- data/credy.gemspec +4 -4
- data/lib/credy.rb +11 -14
- data/lib/credy/check.rb +5 -5
- data/lib/credy/rules.rb +8 -9
- data/lib/credy/version.rb +1 -1
- data/readme.md +26 -26
- data/spec/bin/credy_spec.rb +0 -8
- data/spec/lib/credy/check_spec.rb +4 -8
- data/spec/lib/credy/rules_spec.rb +17 -17
- data/spec/lib/credy/version_spec.rb +0 -2
- data/spec/lib/credy_spec.rb +8 -16
- data/spec/spec_helper.rb +0 -6
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c1d9ed3a0da6fdd31acd12474782f5c9c0509e8
|
4
|
+
data.tar.gz: ef8f0cde519444af8ea026d4a18ee89292149edd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3b149b4e0bf0e83ef854da73dee3a8c25392bb1fca65a99e52f520265f35390e09132b6cc2e3630cf13e1d7265fe18602bad3db5581085b62d937d6bc3b3f5c
|
7
|
+
data.tar.gz: a788b494a479f976bb68cbaaa03354c4bfde0f6ac51d46277449dc633bad439cfc9c42e76bb4382cc3bd23f45533370f6c132d6ee31aa4f242c5bb53fedb9ace
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,36 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
credy (0.
|
5
|
-
thor (~> 0.
|
4
|
+
credy (0.2.1)
|
5
|
+
thor (~> 0.19.1)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
10
|
diff-lcs (1.2.5)
|
11
|
-
rake (10.
|
12
|
-
rspec (
|
13
|
-
rspec-core (~>
|
14
|
-
rspec-expectations (~>
|
15
|
-
rspec-mocks (~>
|
16
|
-
rspec-core (
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
rake (10.4.2)
|
12
|
+
rspec (3.3.0)
|
13
|
+
rspec-core (~> 3.3.0)
|
14
|
+
rspec-expectations (~> 3.3.0)
|
15
|
+
rspec-mocks (~> 3.3.0)
|
16
|
+
rspec-core (3.3.1)
|
17
|
+
rspec-support (~> 3.3.0)
|
18
|
+
rspec-expectations (3.3.0)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.3.0)
|
21
|
+
rspec-mocks (3.3.1)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.3.0)
|
24
|
+
rspec-support (3.3.0)
|
25
|
+
thor (0.19.1)
|
21
26
|
|
22
27
|
PLATFORMS
|
23
28
|
ruby
|
24
29
|
|
25
30
|
DEPENDENCIES
|
26
31
|
credy!
|
27
|
-
rake (~> 10.
|
28
|
-
rspec (~>
|
32
|
+
rake (~> 10.4.2)
|
33
|
+
rspec (~> 3.3.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
1.10.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tim Petricola
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/credy.gemspec
CHANGED
@@ -5,7 +5,7 @@ require File.expand_path '../lib/credy/version', __FILE__
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.authors = ['Tim Petricola']
|
7
7
|
s.email = ['hi@timpetricola.com']
|
8
|
-
s.summary =
|
8
|
+
s.summary = 'Simple credit card number generator'
|
9
9
|
s.license = 'MIT'
|
10
10
|
s.homepage = 'https://github.com/TimPetricola/Credy'
|
11
11
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.require_paths = ['lib']
|
16
16
|
s.version = Credy::VERSION
|
17
17
|
|
18
|
-
s.add_development_dependency 'rspec', '~>
|
19
|
-
s.add_development_dependency 'rake', '~> 10.
|
20
|
-
s.add_runtime_dependency 'thor', '~> 0.
|
18
|
+
s.add_development_dependency 'rspec', '~> 3.3.0'
|
19
|
+
s.add_development_dependency 'rake', '~> 10.4.2'
|
20
|
+
s.add_runtime_dependency 'thor', '~> 0.19.1'
|
21
21
|
end
|
data/lib/credy.rb
CHANGED
@@ -4,15 +4,15 @@ require 'credy/rules'
|
|
4
4
|
require 'credy/check'
|
5
5
|
|
6
6
|
module Credy
|
7
|
-
|
8
7
|
def self.root
|
9
8
|
File.expand_path '../..', __FILE__
|
10
9
|
end
|
11
10
|
|
12
|
-
|
11
|
+
module CreditCard
|
12
|
+
extend self
|
13
13
|
|
14
14
|
# Generate a credit card number
|
15
|
-
def
|
15
|
+
def generate(options = {})
|
16
16
|
rule = find_rule(options) || return
|
17
17
|
number = generate_from_rule(rule)
|
18
18
|
|
@@ -24,7 +24,7 @@ module Credy
|
|
24
24
|
end
|
25
25
|
|
26
26
|
# Returns information about a number
|
27
|
-
def
|
27
|
+
def infos(number)
|
28
28
|
rules = Rules.all.select do |rule|
|
29
29
|
valid = true
|
30
30
|
|
@@ -45,10 +45,10 @@ module Credy
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# Validates a number
|
48
|
-
def
|
48
|
+
def validate(number)
|
49
49
|
criterii = {}
|
50
50
|
criterii[:luhn] = Check.luhn number
|
51
|
-
criterii[:type] = !!
|
51
|
+
criterii[:type] = !!infos(number)
|
52
52
|
|
53
53
|
valid = criterii.all? { |_, v| v == true }
|
54
54
|
|
@@ -58,12 +58,13 @@ module Credy
|
|
58
58
|
}
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
private
|
62
|
+
|
63
|
+
def find_rule(options = {})
|
62
64
|
Rules.filter(options).sample
|
63
65
|
end
|
64
|
-
private_class_method :find_rule
|
65
66
|
|
66
|
-
def
|
67
|
+
def complete_number(number)
|
67
68
|
# Generates the last digit according to luhn algorithm
|
68
69
|
digits = (0..9).map(&:to_s)
|
69
70
|
begin
|
@@ -72,9 +73,8 @@ module Credy
|
|
72
73
|
|
73
74
|
full
|
74
75
|
end
|
75
|
-
private_class_method :complete_number
|
76
76
|
|
77
|
-
def
|
77
|
+
def generate_from_rule(rule)
|
78
78
|
length = Array(rule[:length]).sample
|
79
79
|
number = rule[:prefix]
|
80
80
|
|
@@ -86,8 +86,5 @@ module Credy
|
|
86
86
|
# Append last digit
|
87
87
|
complete_number(number)
|
88
88
|
end
|
89
|
-
private_class_method :generate_from_rule
|
90
|
-
|
91
89
|
end
|
92
|
-
|
93
90
|
end
|
data/lib/credy/check.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
module Credy
|
2
|
+
module Check
|
3
|
+
extend self
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
def self.luhn(code)
|
5
|
+
def luhn(code)
|
6
6
|
s1 = s2 = 0
|
7
|
+
|
7
8
|
code.to_s.reverse.chars.each_slice(2) do |odd, even|
|
8
9
|
s1 += odd.to_i
|
9
10
|
|
@@ -11,9 +12,8 @@ module Credy
|
|
11
12
|
double -= 9 if double >= 10
|
12
13
|
s2 += double
|
13
14
|
end
|
15
|
+
|
14
16
|
(s1 + s2) % 10 == 0
|
15
17
|
end
|
16
|
-
|
17
18
|
end
|
18
|
-
|
19
19
|
end
|
data/lib/credy/rules.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
|
3
3
|
module Credy
|
4
|
-
|
5
|
-
|
4
|
+
module Rules
|
5
|
+
extend self
|
6
6
|
|
7
7
|
# Return all the rules from yml files
|
8
|
-
def
|
8
|
+
def raw
|
9
9
|
@rules ||= load_rules("#{Credy.root}/data/*.yml")
|
10
10
|
end
|
11
11
|
|
12
12
|
# Change hash format to process rules
|
13
|
-
def
|
13
|
+
def all
|
14
14
|
rules = []
|
15
15
|
|
16
16
|
raw.each do |type, details|
|
@@ -43,7 +43,7 @@ module Credy
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# Returns rules according to given filters
|
46
|
-
def
|
46
|
+
def filter(filters = {})
|
47
47
|
all.select do |rule|
|
48
48
|
[:country, :type].each do |condition|
|
49
49
|
break false if filters[condition] && filters[condition] != rule[condition]
|
@@ -52,15 +52,14 @@ module Credy
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
private
|
56
|
+
|
57
|
+
def load_rules(files)
|
56
58
|
{}.tap do |rules|
|
57
59
|
Dir.glob(files) do |filename|
|
58
60
|
rules.merge! YAML::load IO.read(filename)
|
59
61
|
end
|
60
62
|
end
|
61
63
|
end
|
62
|
-
private_class_method :load_rules
|
63
|
-
|
64
64
|
end
|
65
|
-
|
66
65
|
end
|
data/lib/credy/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Credy [](https://travis-ci.org/TimPetricola/Credy) [](http://badge.fury.io/rb/credy) [](https://codeclimate.com/github/TimPetricola/Credy)
|
2
2
|
|
3
|
-
|
3
|
+
Simple credit card generator/validator.
|
4
4
|
Need a valid credit card number to sign up on a site but you don't want to use your real card?
|
5
5
|
Need to validate your customers credit card?
|
6
6
|
|
@@ -56,39 +56,39 @@ Credy::CreditCard.validate '5108756163954799'
|
|
56
56
|
At the moment, only a few types and countries are (partially) supported.
|
57
57
|
|
58
58
|
### Types
|
59
|
-
* americanexpress
|
60
|
-
* bankcard
|
61
|
-
* china-unionpay
|
62
|
-
* diners-club-carte-blanche
|
63
|
-
* diners-club-enroute
|
64
|
-
* diners-club-international
|
65
|
-
* diners-club-us-ca
|
66
|
-
* instapayment
|
67
|
-
* jcb
|
68
|
-
* laser
|
69
|
-
* maestro
|
70
|
-
* mastercard
|
71
|
-
* solo
|
72
|
-
* switch
|
73
|
-
* visa
|
74
|
-
* visa-electron
|
59
|
+
* `americanexpress`: American Express
|
60
|
+
* `bankcard`: Bankcard
|
61
|
+
* `china-unionpay`: China UnionPay
|
62
|
+
* `diners-club-carte-blanche`: Diners Club Carte Blanche
|
63
|
+
* `diners-club-enroute`: Diners Club enRoute
|
64
|
+
* `diners-club-international`: Diners Club International
|
65
|
+
* `diners-club-us-ca`: Diners Club United States & Canada
|
66
|
+
* `instapayment`: InstaPayment
|
67
|
+
* `jcb`: JCB
|
68
|
+
* `laser`: Laser
|
69
|
+
* `maestro`: Maestro
|
70
|
+
* `mastercard`: Mastercard
|
71
|
+
* `solo`: Solo
|
72
|
+
* `switch`: Switch
|
73
|
+
* `visa`: Visa
|
74
|
+
* `visa-electron`: Visa Electron
|
75
75
|
|
76
76
|
### Countries
|
77
|
-
* au
|
78
|
-
* ca
|
79
|
-
* fr
|
80
|
-
* pl
|
81
|
-
* es
|
82
|
-
* ch
|
83
|
-
* uk
|
84
|
-
* us
|
77
|
+
* `au`: Australia
|
78
|
+
* `ca`: Canada
|
79
|
+
* `fr`: France
|
80
|
+
* `pl`: Poland
|
81
|
+
* `es`: Spain
|
82
|
+
* `ch`: Switzerland
|
83
|
+
* `uk`: United Kingdom
|
84
|
+
* `us`: United States
|
85
85
|
|
86
86
|
## Todo
|
87
87
|
* Add more data (see the Data source section)
|
88
88
|
* Remove luhn validation for *China UnionPay* and *Diners Club enRoute*
|
89
89
|
|
90
90
|
## Data source
|
91
|
-
All data is coming from the [Bank card number](http://en.wikipedia.org/wiki/Bank_card_number) page and the [List of Issuer Identification Numbers](http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers) on
|
91
|
+
All data is coming from the [Bank card number](http://en.wikipedia.org/wiki/Bank_card_number) page and the now deleted [List of Issuer Identification Numbers](http://en.wikipedia.org/wiki/List_of_Issuer_Identification_Numbers) on Wikipedia. I do not assume the responsibility for wrong data.
|
92
92
|
|
93
93
|
## License
|
94
94
|
Credy is released under the [MIT License](http://opensource.org/licenses/MIT).
|
data/spec/bin/credy_spec.rb
CHANGED
@@ -2,13 +2,11 @@ require_relative '../spec_helper'
|
|
2
2
|
silent { load 'bin/credy' }
|
3
3
|
|
4
4
|
describe Credy::CLI do
|
5
|
-
|
6
5
|
before(:all) do
|
7
6
|
@stdout, $stdout = $stdout, StringIO.new
|
8
7
|
end
|
9
8
|
|
10
9
|
describe 'generate' do
|
11
|
-
|
12
10
|
it 'works without options' do
|
13
11
|
expect(Credy::CreditCard).to receive(:generate).with({})
|
14
12
|
r = Credy::CLI.start ['generate']
|
@@ -58,13 +56,10 @@ describe Credy::CLI do
|
|
58
56
|
expect(output).to eq "50076645747856835 (visa, au)\n"*2
|
59
57
|
end
|
60
58
|
end
|
61
|
-
|
62
59
|
end
|
63
|
-
|
64
60
|
end
|
65
61
|
|
66
62
|
describe 'infos' do
|
67
|
-
|
68
63
|
it 'calls the infos function' do
|
69
64
|
expect(Credy::CreditCard).to receive(:infos).with '5108756163954799'
|
70
65
|
silent {
|
@@ -86,7 +81,6 @@ describe Credy::CLI do
|
|
86
81
|
expect(output).to eq "Type: visa\nCountry: au\nValid\n"
|
87
82
|
end
|
88
83
|
end
|
89
|
-
|
90
84
|
end
|
91
85
|
|
92
86
|
describe 'validate' do
|
@@ -109,8 +103,6 @@ describe Credy::CLI do
|
|
109
103
|
output = silent { Credy::CLI.start ['validate', '5108756163954799'] }
|
110
104
|
expect(output).to eq "This number is not valid.\n(luhn: x, type: x)\n"
|
111
105
|
end
|
112
|
-
|
113
106
|
end
|
114
107
|
end
|
115
|
-
|
116
108
|
end
|
@@ -1,19 +1,15 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
|
3
3
|
describe Credy::Check do
|
4
|
-
|
5
4
|
describe '.luhn' do
|
6
|
-
|
7
5
|
it 'returns true for correct data' do
|
8
|
-
expect(Credy::Check.luhn(49927398716)).to
|
9
|
-
expect(Credy::Check.luhn(1234567812345670)).to
|
6
|
+
expect(Credy::Check.luhn(49927398716)).to be_truthy
|
7
|
+
expect(Credy::Check.luhn(1234567812345670)).to be_truthy
|
10
8
|
end
|
11
9
|
|
12
10
|
it 'returns false for non correct data' do
|
13
|
-
expect(Credy::Check.luhn(49927398717)).to
|
14
|
-
expect(Credy::Check.luhn(1234567812345678)).to
|
11
|
+
expect(Credy::Check.luhn(49927398717)).to be_falsey
|
12
|
+
expect(Credy::Check.luhn(1234567812345678)).to be_falsey
|
15
13
|
end
|
16
|
-
|
17
14
|
end
|
18
|
-
|
19
15
|
end
|
@@ -1,20 +1,23 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
|
3
3
|
describe Credy::Rules do
|
4
|
-
|
5
4
|
subject { Credy::Rules }
|
6
5
|
|
7
6
|
describe '.raw' do
|
8
7
|
it { should respond_to :raw }
|
9
|
-
|
8
|
+
|
9
|
+
it 'is a hash' do
|
10
|
+
expect(subject.raw).to be_a Hash
|
11
|
+
end
|
10
12
|
end
|
11
13
|
|
12
14
|
describe '.all' do
|
13
|
-
|
14
|
-
|
15
|
+
it 'is a array' do
|
16
|
+
expect(subject.all).to be_a Array
|
17
|
+
end
|
15
18
|
|
16
19
|
it 'contains a set of rules' do
|
17
|
-
subject.
|
20
|
+
allow(subject).to receive(:raw).and_return({
|
18
21
|
'visa' => {
|
19
22
|
'length' => [13, 16],
|
20
23
|
'countries' => {
|
@@ -36,7 +39,7 @@ describe Credy::Rules do
|
|
36
39
|
end
|
37
40
|
|
38
41
|
it 'works with string prefixes' do
|
39
|
-
subject.
|
42
|
+
allow(subject).to receive(:raw).and_return({
|
40
43
|
'visa' => {
|
41
44
|
'length' => [13, 16],
|
42
45
|
'countries' => {
|
@@ -51,7 +54,7 @@ describe Credy::Rules do
|
|
51
54
|
end
|
52
55
|
|
53
56
|
it 'works with integer prefixes' do
|
54
|
-
subject.
|
57
|
+
allow(subject).to receive(:raw).and_return({
|
55
58
|
'visa' => {
|
56
59
|
'length' => [13, 16],
|
57
60
|
'countries' => {
|
@@ -66,7 +69,7 @@ describe Credy::Rules do
|
|
66
69
|
end
|
67
70
|
|
68
71
|
it 'works with an array of prefixes' do
|
69
|
-
subject.
|
72
|
+
allow(subject).to receive(:raw).and_return({
|
70
73
|
'visa' => {
|
71
74
|
'length' => [13, 16],
|
72
75
|
'countries' => {
|
@@ -84,9 +87,8 @@ describe Credy::Rules do
|
|
84
87
|
end
|
85
88
|
|
86
89
|
describe '.filter' do
|
87
|
-
|
88
90
|
before do
|
89
|
-
subject.
|
91
|
+
allow(subject).to receive(:raw).and_return({
|
90
92
|
'visa' => {
|
91
93
|
'length' => [13, 16],
|
92
94
|
'countries' => {
|
@@ -111,18 +113,18 @@ describe Credy::Rules do
|
|
111
113
|
end
|
112
114
|
|
113
115
|
it 'filters by type' do
|
114
|
-
expect(subject.filter(type: 'visa')).to
|
115
|
-
expect(subject.filter(type: 'mastercard')).to
|
116
|
+
expect(subject.filter(type: 'visa').length).to eq 2
|
117
|
+
expect(subject.filter(type: 'mastercard').length).to eq 1
|
116
118
|
end
|
117
119
|
|
118
120
|
it 'accepts the :country option' do
|
119
|
-
expect(subject.filter(country: 'ch')).to
|
120
|
-
expect(subject.filter(country: 'au')).to
|
121
|
+
expect(subject.filter(country: 'ch').length).to eq 1
|
122
|
+
expect(subject.filter(country: 'au').length).to eq 2
|
121
123
|
end
|
122
124
|
|
123
125
|
it 'accepts several options at the same time' do
|
124
126
|
rules = subject.filter type: 'visa', country: 'au'
|
125
|
-
expect(rules).to
|
127
|
+
expect(rules.length).to eq 1
|
126
128
|
end
|
127
129
|
|
128
130
|
it 'returns an empty array if nothing is found' do
|
@@ -130,7 +132,5 @@ describe Credy::Rules do
|
|
130
132
|
expect(rules).to be_a Array
|
131
133
|
expect(rules).to be_empty
|
132
134
|
end
|
133
|
-
|
134
135
|
end
|
135
|
-
|
136
136
|
end
|
data/spec/lib/credy_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe Credy::CreditCard do
|
4
|
-
|
5
4
|
subject { Credy::CreditCard }
|
6
5
|
|
7
6
|
let(:rules) do
|
@@ -24,11 +23,10 @@ describe Credy::CreditCard do
|
|
24
23
|
end
|
25
24
|
|
26
25
|
before(:each) do
|
27
|
-
Credy::Rules.
|
26
|
+
allow(Credy::Rules).to receive(:raw).and_return rules
|
28
27
|
end
|
29
28
|
|
30
29
|
describe '.generate' do
|
31
|
-
|
32
30
|
it 'returns a number, type and country' do
|
33
31
|
expect(subject.generate[:number]).not_to be_nil
|
34
32
|
expect(subject.generate[:type]).not_to be_nil
|
@@ -65,40 +63,34 @@ describe Credy::CreditCard do
|
|
65
63
|
number = subject.generate type: 'foo', country: 'bar'
|
66
64
|
expect(number).to be_nil
|
67
65
|
end
|
68
|
-
|
69
66
|
end
|
70
67
|
|
71
68
|
describe '.infos' do
|
72
|
-
|
73
69
|
it 'returns the correct information according to the card number' do
|
74
70
|
infos = subject.infos '5108756163954792'
|
75
71
|
expect(infos[:type]).to eq 'mastercard'
|
76
72
|
expect(infos[:country]).to eq 'us'
|
77
73
|
end
|
78
|
-
|
79
74
|
end
|
80
75
|
|
81
76
|
describe '.validate' do
|
82
|
-
|
83
77
|
it 'returns a hash' do
|
84
78
|
r = subject.validate '5108756163954792'
|
85
|
-
expect(r[:valid]).to
|
86
|
-
expect(r[:details][:luhn]).to
|
87
|
-
expect(r[:details][:type]).to
|
79
|
+
expect(r[:valid]).to be_truthy
|
80
|
+
expect(r[:details][:luhn]).to be_truthy
|
81
|
+
expect(r[:details][:type]).to be_truthy
|
88
82
|
end
|
89
83
|
|
90
84
|
it 'checks against luhn algorithm' do
|
91
85
|
r = subject.validate '5108756163954791'
|
92
|
-
expect(r[:valid]).to
|
93
|
-
expect(r[:details][:luhn]).to
|
86
|
+
expect(r[:valid]).to be_falsey
|
87
|
+
expect(r[:details][:luhn]).to be_falsey
|
94
88
|
end
|
95
89
|
|
96
90
|
it 'checks against card type' do
|
97
91
|
r = subject.validate '99999999999999999999992'
|
98
|
-
expect(r[:valid]).to
|
99
|
-
expect(r[:details][:type]).to
|
92
|
+
expect(r[:valid]).to be_falsey
|
93
|
+
expect(r[:details][:type]).to be_falsey
|
100
94
|
end
|
101
|
-
|
102
95
|
end
|
103
|
-
|
104
96
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: credy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Petricola
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.3.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.3.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 10.
|
33
|
+
version: 10.4.2
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 10.
|
40
|
+
version: 10.4.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.19.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.19.1
|
55
55
|
description:
|
56
56
|
email:
|
57
57
|
- hi@timpetricola.com
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- ".travis.yml"
|
65
65
|
- Gemfile
|
66
66
|
- Gemfile.lock
|
67
|
+
- LICENSE
|
67
68
|
- Rakefile
|
68
69
|
- bin/credy
|
69
70
|
- credy.gemspec
|
@@ -115,10 +116,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
116
|
version: '0'
|
116
117
|
requirements: []
|
117
118
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.
|
119
|
+
rubygems_version: 2.4.5
|
119
120
|
signing_key:
|
120
121
|
specification_version: 4
|
121
|
-
summary:
|
122
|
+
summary: Simple credit card number generator
|
122
123
|
test_files:
|
123
124
|
- spec/bin/credy_spec.rb
|
124
125
|
- spec/lib/credy/check_spec.rb
|