credit_card_inspector 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c73227676fcccc167a07ac46c3c6d73e7e38956b
4
+ data.tar.gz: 04414bbcfdc23a90271a388f875748aa0a7d0557
5
+ SHA512:
6
+ metadata.gz: f22cc8ce9bc4a57bfef754187966df153773e41da9d146dbca9391b5b6e72c3ac4741350efa4f5d4b31915e0e035a3830d0b0f1a073532ce9e8ac4e5a0ab66df
7
+ data.tar.gz: ac7bf310d66ffd97ad44c3a8a345280e8fae9d36b4948f76a73dfb7d940f6e068838a19091a9ff36be9af67e32ee5804a4b41bf40e9d1666fb0b8da2a8ce047a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in credit_card_inspector.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Steve Lorek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Credit Card Inspector
2
+
3
+ Validate a credit card number according to the [Luhn algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm). Also determine the type of credit card by its number (AMEX, Discover, MaserCard and Visa).
4
+
5
+ Tested in Ruby 1.8.7, 1.9.2, 1.9.3 and 2.0.0.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'credit_card_inspector'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install credit_card_inspector
20
+
21
+ ## Usage
22
+
23
+ ### Validate Card number
24
+
25
+ Call `CreditCardInspector.valid?(card_number)`. This will return true or false representing the card's validity.
26
+
27
+ ### Determine Card type
28
+
29
+ Call `CreditCardInspector.card_type(card_number)`. This will return a string representing the card type. Possible return values are:
30
+
31
+ - VISA
32
+ - AMEX
33
+ - Discover
34
+ - MasterCard
35
+ - Unknown
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task default: :spec
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe CreditCardInspector do
4
+
5
+ let(:visa_valid) { ['4012888888881881', '4111111111111111'] }
6
+ let(:visa_invalid) { '4111111111111' }
7
+ let(:amex_valid) { '378282246310005' }
8
+ let(:discover_valid) { '6011111111111117' }
9
+ let(:mastercard_valid) { '5105105105105100' }
10
+ let(:mastercard_invalid) { '5105 1051 0510 5106' }
11
+ let(:unknown_card) { '9111111111111111' }
12
+
13
+ describe '.card_type' do
14
+ it 'matches VISA cards' do
15
+ (visa_valid << visa_invalid).each do |card|
16
+ described_class.card_type(card).should == 'VISA'
17
+ end
18
+ end
19
+
20
+ it 'matches AMEX cards' do
21
+ described_class.card_type(amex_valid).should == 'AMEX'
22
+ end
23
+
24
+ it 'matches Discover cards' do
25
+ described_class.card_type(discover_valid).should == 'Discover'
26
+ end
27
+
28
+ it 'matches MasterCard cards' do
29
+ [mastercard_valid, mastercard_invalid].each do |card|
30
+ described_class.card_type(card).should == 'MasterCard'
31
+ end
32
+ end
33
+
34
+ it 'returns "Unknown" when no match is found' do
35
+ described_class.card_type(unknown_card).should == 'Unknown'
36
+ end
37
+ end
38
+
39
+ describe '.valid?' do
40
+ it 'correctly identifies valid card numbers' do
41
+ (visa_valid | [amex_valid, discover_valid, mastercard_valid]).each do |card|
42
+ described_class.valid?(card).should == true
43
+ end
44
+ end
45
+
46
+ it 'correctly identifies invalid card numbers' do
47
+ [visa_invalid, mastercard_invalid].each do |card|
48
+ described_class.valid?(card).should == false
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '.sanitise_card_number' do
54
+ it 'strips all non-numeric characters' do
55
+ described_class.sanitise_card_number(mastercard_invalid).should == '5105105105105106'
56
+ end
57
+ end
58
+ end
@@ -0,0 +1 @@
1
+ require 'credit_card_inspector'
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: credit_card_inspector
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Steve Lorek
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-03-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Credit Card Inspector
56
+ email:
57
+ - steve@stevelorek.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - CHANGELOG
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - spec/credit_card_validator_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: ''
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.0
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Validates credit cards according to the Luhn algorithm. Also determines the
95
+ type of card from its number
96
+ test_files:
97
+ - spec/credit_card_validator_spec.rb
98
+ - spec/spec_helper.rb