plastic 0.2.1 → 0.2.2

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/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  *.gem
2
- *.gemspec
3
2
  *.log
4
3
  *.pid
5
4
  *.sqlite3
@@ -4,7 +4,7 @@ Credit card “plastic” library for Ruby. Parses track 1, track 2 and individu
4
4
 
5
5
  == Prerequisites
6
6
 
7
- * Money and a FICA score > 600.
7
+ * Money and a FICO score > 600.
8
8
 
9
9
  == Testing
10
10
 
@@ -1,5 +1,5 @@
1
1
  class Plastic
2
- BRANDS = [:visa, :mastercard, :american_express, :discover]
2
+ BRANDS = [:visa, :mastercard, :american_express, :discover, :jcb]
3
3
 
4
4
  attr_accessor :pan, :expiration
5
5
  attr_accessor :track_name, :surname, :given_name, :title
@@ -40,12 +40,15 @@ class Plastic
40
40
 
41
41
  def brand
42
42
  case pan
43
- when /^4/ then :visa
44
- when /^5[1-5]/ then :mastercard
45
- when /^677189/ then :mastercard
46
- when /^6011/ then :discover
47
- when /^65/ then :discover
48
- when /^3[47]/ then :american_express
43
+ when /^4\d{15}$/ then :visa
44
+ when /^5[1-5]\d{14}$/ then :mastercard
45
+ when /^677189\d{10}$/ then :mastercard
46
+ when /^6011\d{12}$/ then :discover
47
+ when /^64[4-9]\d{13}$/ then :discover
48
+ when /^65\d{14}$/ then :discover
49
+ when /^3[47]\d{13}$/ then :american_express
50
+ when /^352[8-9]\d{12}$/ then :jcb
51
+ when /^35[3-8]\d{13}$/ then :jcb
49
52
  end
50
53
  end
51
54
 
@@ -2,7 +2,7 @@ class Plastic
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,62 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{plastic}
8
+ s.version = "0.2.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Randy Reddig", "Cameron Walters", "Chris Kampmeier", "Erica Kwan", "Matthew O'Connor", "Damon McCormick", "Brian Jenkins"]
12
+ s.date = %q{2010-09-01}
13
+ s.description = %q{Handle credit, debit, bank and other cards.}
14
+ s.email = %q{github@squareup.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "HISTORY.rdoc",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "lib/plastic.rb",
26
+ "lib/plastic/core.rb",
27
+ "lib/plastic/duck_type.rb",
28
+ "lib/plastic/track.rb",
29
+ "lib/plastic/validations.rb",
30
+ "lib/plastic/version.rb",
31
+ "plastic.gemspec",
32
+ "spec/plastic/core_spec.rb",
33
+ "spec/plastic/duck_type_spec.rb",
34
+ "spec/plastic/track_spec.rb",
35
+ "spec/plastic/validations_spec.rb",
36
+ "spec/spec.opts",
37
+ "spec/spec_helper.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/square/plastic}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.7}
43
+ s.summary = %q{Credit card library for Ruby.}
44
+ s.test_files = [
45
+ "spec/plastic/core_spec.rb",
46
+ "spec/plastic/duck_type_spec.rb",
47
+ "spec/plastic/track_spec.rb",
48
+ "spec/plastic/validations_spec.rb",
49
+ "spec/spec_helper.rb"
50
+ ]
51
+
52
+ if s.respond_to? :specification_version then
53
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
+ s.specification_version = 3
55
+
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
+ else
58
+ end
59
+ else
60
+ end
61
+ end
62
+
@@ -155,37 +155,108 @@ describe Plastic do
155
155
  Plastic.new(:pan => "4111111111111111").brand.should == :visa
156
156
  end
157
157
 
158
+ it "does not recognize pseudo-Visa cards with 13, 14, 15, or 17 digits" do
159
+ # Visa once used 13-digit PANs, but these accounts have all been migrated
160
+ # to 16-digit PANs. The old numbers are not valid for new transactions.
161
+ Plastic.new(:pan => "4111111111111").brand.should_not == :visa
162
+ Plastic.new(:pan => "41111111111111").brand.should_not == :visa
163
+ Plastic.new(:pan => "411111111111111").brand.should_not == :visa
164
+ Plastic.new(:pan => "41111111111111111").brand.should_not == :visa
165
+ end
166
+
158
167
  it "recognizes MasterCard cards" do
159
168
  Plastic.new(:pan => "5100000000000000").brand.should == :mastercard
160
169
  Plastic.new(:pan => "5200000000000000").brand.should == :mastercard
161
170
  Plastic.new(:pan => "5300000000000000").brand.should == :mastercard
162
171
  Plastic.new(:pan => "5400000000000000").brand.should == :mastercard
163
172
  Plastic.new(:pan => "5500000000000000").brand.should == :mastercard
164
- Plastic.new(:pan => "6771890000000000").brand.should == :mastercard # TODO: confirm that 6771- is really MasterCard
173
+ # TODO: confirm that 677189- is really MasterCard
174
+ Plastic.new(:pan => "6771890000000000").brand.should == :mastercard
175
+ end
176
+
177
+ it "does not recognize pseudo-MasterCards with invalid IINs" do
178
+ Plastic.new(:pan => "5000000000000000").brand.should_not == :mastercard
179
+ Plastic.new(:pan => "5600000000000000").brand.should_not == :mastercard
180
+ Plastic.new(:pan => "5700000000000000").brand.should_not == :mastercard
181
+ Plastic.new(:pan => "5800000000000000").brand.should_not == :mastercard
182
+ Plastic.new(:pan => "5900000000000000").brand.should_not == :mastercard
165
183
  end
166
184
 
167
- it "returns nil for bogus pseudo-MasterCard cards" do
168
- Plastic.new(:pan => "5000000000000000").brand.should be_nil
169
- Plastic.new(:pan => "5600000000000000").brand.should be_nil
170
- Plastic.new(:pan => "5700000000000000").brand.should be_nil
171
- Plastic.new(:pan => "5800000000000000").brand.should be_nil
172
- Plastic.new(:pan => "5900000000000000").brand.should be_nil
185
+ it "does not recognize pseudo-MasterCards with 15 or 17 digits" do
186
+ Plastic.new(:pan => "510000000000000").brand.should_not == :mastercard
187
+ Plastic.new(:pan => "520000000000000").brand.should_not == :mastercard
188
+ Plastic.new(:pan => "53000000000000000").brand.should_not == :mastercard
189
+ Plastic.new(:pan => "54000000000000000").brand.should_not == :mastercard
190
+ # TODO: confirm that 677189- is really MasterCard
191
+ Plastic.new(:pan => "677189000000000").brand.should_not == :mastercard
192
+ Plastic.new(:pan => "67718900000000000").brand.should_not == :mastercard
173
193
  end
174
194
 
175
195
  it "recognizes Discover cards" do
176
196
  Plastic.new(:pan => "6011000000000000").brand.should == :discover
197
+ Plastic.new(:pan => "6440000000000000").brand.should == :discover
198
+ Plastic.new(:pan => "6450000000000000").brand.should == :discover
199
+ Plastic.new(:pan => "6460000000000000").brand.should == :discover
200
+ Plastic.new(:pan => "6470000000000000").brand.should == :discover
201
+ Plastic.new(:pan => "6480000000000000").brand.should == :discover
202
+ Plastic.new(:pan => "6490000000000000").brand.should == :discover
177
203
  Plastic.new(:pan => "6500000000000000").brand.should == :discover
178
204
  end
179
205
 
206
+ it "does not recognize pseudo-Discover cards with 15 digits" do
207
+ Plastic.new(:pan => "601100000000000").brand.should_not == :discover
208
+ Plastic.new(:pan => "644000000000000").brand.should_not == :discover
209
+ Plastic.new(:pan => "645000000000000").brand.should_not == :discover
210
+ Plastic.new(:pan => "646000000000000").brand.should_not == :discover
211
+ Plastic.new(:pan => "647000000000000").brand.should_not == :discover
212
+ Plastic.new(:pan => "648000000000000").brand.should_not == :discover
213
+ Plastic.new(:pan => "649000000000000").brand.should_not == :discover
214
+ Plastic.new(:pan => "650000000000000").brand.should_not == :discover
215
+ end
216
+
217
+ it "does not recognize pseudo-Discover cards with 17 digits" do
218
+ Plastic.new(:pan => "60110000000000000").brand.should_not == :discover
219
+ Plastic.new(:pan => "64400000000000000").brand.should_not == :discover
220
+ Plastic.new(:pan => "64500000000000000").brand.should_not == :discover
221
+ Plastic.new(:pan => "64600000000000000").brand.should_not == :discover
222
+ Plastic.new(:pan => "64700000000000000").brand.should_not == :discover
223
+ Plastic.new(:pan => "64800000000000000").brand.should_not == :discover
224
+ Plastic.new(:pan => "64900000000000000").brand.should_not == :discover
225
+ Plastic.new(:pan => "65000000000000000").brand.should_not == :discover
226
+ end
227
+
180
228
  it "recognizes American Express cards" do
181
229
  Plastic.new(:pan => "340000000000000").brand.should == :american_express
182
230
  Plastic.new(:pan => "370000000000000").brand.should == :american_express
183
231
  end
232
+
233
+ it "does not recognize pseudo-American Express cards with 14 or 16 digits" do
234
+ Plastic.new(:pan => "34000000000000").brand.should_not == :american_express
235
+ Plastic.new(:pan => "37000000000000").brand.should_not == :american_express
236
+ Plastic.new(:pan => "3400000000000000").brand.should_not == :american_express
237
+ Plastic.new(:pan => "3700000000000000").brand.should_not == :american_express
238
+ end
239
+
240
+ it "recognizes JCB cards" do
241
+ Plastic.new(:pan => "3540123456789012").brand.should == :jcb
242
+ Plastic.new(:pan => "3528000000000000").brand.should == :jcb
243
+ Plastic.new(:pan => "3589990000000000").brand.should == :jcb
244
+ end
245
+
246
+ it "does not recognize pseudo-JCB cards with 15 or 17 digits" do
247
+ Plastic.new(:pan => "354012345678901").brand.should_not == :jcb
248
+ Plastic.new(:pan => "352800000000000").brand.should_not == :jcb
249
+ Plastic.new(:pan => "358999000000000").brand.should_not == :jcb
250
+ Plastic.new(:pan => "35401234567890123").brand.should_not == :jcb
251
+ Plastic.new(:pan => "35280000000000000").brand.should_not == :jcb
252
+ Plastic.new(:pan => "35899900000000000").brand.should_not == :jcb
253
+ end
184
254
  end
185
255
 
186
256
  describe "BRANDS constant" do
187
257
  it "returns a list of the brands as symbols" do
188
- Plastic::BRANDS.should == [:visa, :mastercard, :american_express, :discover]
258
+ Plastic::BRANDS.should == [:visa, :mastercard, :american_express,
259
+ :discover, :jcb]
189
260
  end
190
261
  end
191
262
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plastic
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 1
10
- version: 0.2.1
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Randy Reddig
@@ -21,7 +21,7 @@ autorequire:
21
21
  bindir: bin
22
22
  cert_chain: []
23
23
 
24
- date: 2010-07-18 00:00:00 -07:00
24
+ date: 2010-09-01 00:00:00 -07:00
25
25
  default_executable:
26
26
  dependencies: []
27
27
 
@@ -46,6 +46,7 @@ files:
46
46
  - lib/plastic/track.rb
47
47
  - lib/plastic/validations.rb
48
48
  - lib/plastic/version.rb
49
+ - plastic.gemspec
49
50
  - spec/plastic/core_spec.rb
50
51
  - spec/plastic/duck_type_spec.rb
51
52
  - spec/plastic/track_spec.rb