magnet 1.5.0 → 1.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/lib/magnet/card.rb +1 -1
- data/lib/magnet/parser.rb +17 -9
- data/lib/magnet/version.rb +1 -1
- data/test/magnet/card_parser_test.rb +47 -0
- data/test/magnet/parser_test.rb +46 -0
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MzY0M2E2ZmUyOTNiMDM5Y2E2N2E0NjVkYWQwY2MwNGYxNTUxOWM5Mg==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 949bdc5e5fd0ef2d97ca63f613ba3251762f90c8
|
4
|
+
data.tar.gz: 6e065fb9d6a34fdb7a1d56a906816cdfe9f2aa4f
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZDEyODAzN2JhYTg3ZDMzNWM4ODdlNWM4OGRiOTliMjQ2YjYyZjQ5MDBjZTBi
|
11
|
-
OTY0MGRlZTJkZWY4YWRmNTAzZDZkYmNlNzlkZGEyYmRmMGU1OWU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NjE0MTM1MjVlZGVmNDcxNWNhMjE3OTFkZTQzNzJkY2ZmOThlNjQ2NDE5MGE0
|
14
|
-
N2I5MWMwNzE3MzJjN2M5ZTRmZDg2YjFhYjljNGJjZWE3MzRjNmJmY2U3ZTU2
|
15
|
-
NzlmNTg4MWEwMzJhOWE3Yzc1ZjgxYjk0M2M1NjNhZjVmZGZhODA=
|
6
|
+
metadata.gz: dad20f9f02191d065fb212b20d5466f5078700bbe782ff481259cd4704bdaf9ca754a5b5e5f5e54e2c0aa62a6b993006d7b3334d83b3632c0a92c97cc816a3f2
|
7
|
+
data.tar.gz: 84397f173c18f21e1e44deef8ae12611cb4308a36257547681bb287c3e3ed716ae16fd9343592699c67dece64c5899e557a8091ed0e4436036d9cc019bb1c3fb
|
data/lib/magnet/card.rb
CHANGED
@@ -49,7 +49,7 @@ module Magnet
|
|
49
49
|
attributes = parser.parse(track_data)
|
50
50
|
position1, position2, position3 = (attributes[:service_code] || "").scan(/\d/).map(&:to_i)
|
51
51
|
year, month = (attributes[:expiration] || "").scan(/\d\d/).map(&:to_i)
|
52
|
-
title, first_name, initial, last_name = parse_name(attributes[:name].rstrip)
|
52
|
+
title, first_name, initial, last_name = parse_name(attributes[:name].rstrip) if attributes[:name]
|
53
53
|
|
54
54
|
card = new
|
55
55
|
card.allowed_services = hash_lookup(ALLOWED_SERVICES, position3)
|
data/lib/magnet/parser.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Magnet
|
2
2
|
class Parser
|
3
3
|
TRACKS = {
|
4
|
-
1 => /\A%(?<format>[A-Z])(?<pan>[0-9 ]{1,19})\^(?<name>[^^]*)
|
5
|
-
2 => /\A;(?<
|
4
|
+
1 => /\A%(?<format>[A-Z])(?<pan>[0-9 ]{1,19})\^(?<name>[^^]*)\^\s?(?<expiration>\d{4}|\^)(?<service_code>\d{3}|\^)(?<discretionary_data>[^\?]*)\?\Z/,
|
5
|
+
2 => /\A;(?<pan>[0-9 ]{1,19})=(?<expiration>\d{4}|=)(?<service_code>\d{3}|=)(?<discretionary_data>[^\?]*)\?.?\Z/,
|
6
6
|
}.freeze
|
7
7
|
|
8
8
|
def initialize(track = :auto)
|
@@ -15,13 +15,21 @@ module Magnet
|
|
15
15
|
tracks.each do |track|
|
16
16
|
if m = track.match(track_data)
|
17
17
|
attributes = {}
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
if track == TRACKS[1]
|
19
|
+
attributes[:format] = m[:format]
|
20
|
+
attributes[:pan] = m[:pan]
|
21
|
+
attributes[:name] = m[:name]
|
22
|
+
attributes[:expiration] = m[:expiration] == "^" ? nil : m[:expiration]
|
23
|
+
attributes[:service_code] = m[:service_code] == "^" ? nil : m[:service_code]
|
24
|
+
attributes[:discretionary_data] = m[:discretionary_data] == "" ? nil : m[:discretionary_data]
|
25
|
+
return attributes
|
26
|
+
elsif track == TRACKS[2]
|
27
|
+
attributes[:pan] = m[:pan]
|
28
|
+
attributes[:expiration] = m[:expiration] == "=" ? nil : m[:expiration]
|
29
|
+
attributes[:service_code] = m[:service_code] == "=" ? nil : m[:service_code]
|
30
|
+
attributes[:discretionary_data] = m[:discretionary_data] == "" ? nil : m[:discretionary_data]
|
31
|
+
return attributes
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
data/lib/magnet/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Magnet::Card do
|
4
|
+
describe "Parse" do
|
5
|
+
before do
|
6
|
+
@parser = Magnet::Parser.new(:auto)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "track 2 should work" do
|
10
|
+
track_data = ";4716916000001234=1809901123?"
|
11
|
+
card = Magnet::Card.parse(track_data, @parser)
|
12
|
+
assert_equal "4716916000001234", card.number
|
13
|
+
assert_equal :no_restrictions, card.allowed_services
|
14
|
+
assert_equal :normal, card.authorization_processing
|
15
|
+
assert_equal "123", card.discretionary_data
|
16
|
+
assert_equal 9, card.expiration_month
|
17
|
+
assert_equal 18, card.expiration_year
|
18
|
+
assert_equal :test, card.interchange
|
19
|
+
assert_nil card.first_name
|
20
|
+
assert_nil card.format
|
21
|
+
assert_nil card.initial
|
22
|
+
assert_nil card.last_name
|
23
|
+
assert_nil card.pin_requirements
|
24
|
+
assert_nil card.technology
|
25
|
+
assert_nil card.title
|
26
|
+
end
|
27
|
+
|
28
|
+
it "track 1 should work" do
|
29
|
+
track_data = "%B5452300551227189^HOGAN/PAUL ^08043210000000725000000?"
|
30
|
+
card = Magnet::Card.parse(track_data, @parser)
|
31
|
+
assert_equal "5452300551227189", card.number
|
32
|
+
assert_equal :no_restrictions, card.allowed_services
|
33
|
+
assert_equal :by_issuer, card.authorization_processing
|
34
|
+
assert_equal "0000000725000000", card.discretionary_data
|
35
|
+
assert_equal 4, card.expiration_month
|
36
|
+
assert_equal 8, card.expiration_year
|
37
|
+
assert_nil card.interchange
|
38
|
+
assert_equal "PAUL", card.first_name
|
39
|
+
assert_equal :bank, card.format
|
40
|
+
assert_nil card.initial
|
41
|
+
assert_equal "HOGAN", card.last_name
|
42
|
+
assert_nil card.pin_requirements
|
43
|
+
assert_nil card.technology
|
44
|
+
assert_nil card.title
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/test/magnet/parser_test.rb
CHANGED
@@ -189,5 +189,51 @@ describe Magnet::Parser do
|
|
189
189
|
|
190
190
|
assert_equal "ALISON,MAYNE/B /", attributes[:name]
|
191
191
|
end
|
192
|
+
|
193
|
+
it "should parse track data with space after the second carrot" do
|
194
|
+
attributes = @parser.parse("%B4717270000000000^ALISON MAYNE/B^ 0000000?")
|
195
|
+
assert_equal "ALISON MAYNE/B", attributes[:name]
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "Track 2" do
|
200
|
+
before do
|
201
|
+
@parser = Magnet::Parser.new(2)
|
202
|
+
end
|
203
|
+
it "should parse track 2 data sample #1" do
|
204
|
+
attributes = @parser.parse(";4716916000001234=1809901123?")
|
205
|
+
|
206
|
+
assert_equal "4716916000001234", attributes[:pan]
|
207
|
+
assert_equal "1809", attributes[:expiration]
|
208
|
+
assert_equal "901", attributes[:service_code]
|
209
|
+
assert_equal "123", attributes[:discretionary_data]
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should parse track 2 data sample #2" do
|
213
|
+
attributes = @parser.parse(";5301250070000191=08051010912345678901?")
|
214
|
+
|
215
|
+
assert_equal "5301250070000191", attributes[:pan]
|
216
|
+
assert_equal "0805", attributes[:expiration]
|
217
|
+
assert_equal "101", attributes[:service_code]
|
218
|
+
assert_equal "0912345678901", attributes[:discretionary_data]
|
219
|
+
end
|
220
|
+
|
221
|
+
it "should parse track 2 data sample #3" do
|
222
|
+
attributes = @parser.parse(";3540599999991047=080501234567?")
|
223
|
+
|
224
|
+
assert_equal "3540599999991047", attributes[:pan]
|
225
|
+
assert_equal "0805", attributes[:expiration]
|
226
|
+
assert_equal "012", attributes[:service_code]
|
227
|
+
assert_equal "34567", attributes[:discretionary_data]
|
228
|
+
end
|
229
|
+
|
230
|
+
it "should ignore checksum when parsing track 2" do
|
231
|
+
attributes = @parser.parse(";5413330089020037=1412101050930812??")
|
232
|
+
|
233
|
+
assert_equal "5413330089020037", attributes[:pan]
|
234
|
+
assert_equal "1412", attributes[:expiration]
|
235
|
+
assert_equal "101", attributes[:service_code]
|
236
|
+
assert_equal "050930812", attributes[:discretionary_data]
|
237
|
+
end
|
192
238
|
end
|
193
239
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Kadolph
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 5.0.6
|
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
26
|
version: 5.0.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: mocha
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 0.14.0
|
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
40
|
version: 0.14.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 10.0.3
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 10.0.3
|
55
55
|
description: magnet lets you parse track data from magnetic stripe cards. Currently
|
@@ -60,10 +60,11 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- lib/magnet.rb
|
63
64
|
- lib/magnet/card.rb
|
64
65
|
- lib/magnet/parser.rb
|
65
66
|
- lib/magnet/version.rb
|
66
|
-
-
|
67
|
+
- test/magnet/card_parser_test.rb
|
67
68
|
- test/magnet/card_test.rb
|
68
69
|
- test/magnet/parser_test.rb
|
69
70
|
homepage: http://samuelkadolph.github.com/magnet/
|
@@ -75,20 +76,21 @@ require_paths:
|
|
75
76
|
- lib
|
76
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
78
|
requirements:
|
78
|
-
- -
|
79
|
+
- - ">="
|
79
80
|
- !ruby/object:Gem::Version
|
80
81
|
version: 1.9.2
|
81
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
83
|
requirements:
|
83
|
-
- -
|
84
|
+
- - ">="
|
84
85
|
- !ruby/object:Gem::Version
|
85
86
|
version: '0'
|
86
87
|
requirements: []
|
87
88
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.2.2
|
89
90
|
signing_key:
|
90
91
|
specification_version: 4
|
91
92
|
summary: magnet is a library for decoding the track data on magnetic stripe cards.
|
92
93
|
test_files:
|
93
94
|
- test/magnet/card_test.rb
|
95
|
+
- test/magnet/card_parser_test.rb
|
94
96
|
- test/magnet/parser_test.rb
|