magnet 1.1.0 → 1.2.0

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- N2Y1YzY0NzY3ODgyZDUwOTc2OTE2ZjZkYzEzYjFjYjlhNDhiNDM5Ng==
5
- data.tar.gz: !binary |-
6
- YzExNjVkMDE0MzQxYjQzYTYwN2UxNGNkNGEzMGIwZDdiZjU4ZTc0Ng==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NmM1MzAyNzRmMzdhMTIwZWMxYzI4NWRhMmRlN2E0MDgwOGMwODU5NzE3Yzlj
10
- YzE0YzM0NjBhNDgxMjNjMGI5YTMwMzFhNDVhNjljYWE2ZWViNTYyMzM1NmNk
11
- MDdhYzBlNTVkMWExMDY0ZGQzMDA0MjU1MTZkMDYwMjU5MWVjMTI=
12
- data.tar.gz: !binary |-
13
- ODQ4ODFhYzA5MmQwNzA0OTA1YzM2OWEyZjRhNWRlNGM0ZTljOWI1MWU2YTk3
14
- NWRkZjY3ODAzNGRlYzc5YWI2YWI4YjJlNGZmNjQ5Y2MwMmVjNzQ5MTUzMjQ0
15
- ZmU1NjMxZDJiMTIxNGExMzRkNjdhNjlkNmI0NTE1NWU1MzhhNTQ=
2
+ SHA1:
3
+ metadata.gz: c3717dd5953a1c90ed674b2c92413241a4f53fbf
4
+ data.tar.gz: 229a5f369ae86f31a8b8950fedf5f5e847494377
5
+ SHA512:
6
+ metadata.gz: f8fbb57a6b7a19cf0c4902a1646dd1a6b49c4c5e3331f11edd8287dbbfce5cd80796570f91b8175d388a7eb09f83891641ec937dabbec25d1314d2c91ffe1c57
7
+ data.tar.gz: ce15422bc6904821202f11be135601bc4997c1c50fc4379d52e7d625189b62fb7ab1bee60fdb5f5231b4fd9cc5c1c2691c1bf5524b9c9996aadfbd369912831c
data/lib/magnet/card.rb CHANGED
@@ -62,7 +62,7 @@ module Magnet
62
62
  card.initial = initial
63
63
  card.interchange = hash_lookup(INTERCHANGE, position1)
64
64
  card.last_name = last_name
65
- card.number = attributes[:pan]
65
+ card.number = parse_pan(attributes[:pan])
66
66
  card.pin_requirements = hash_lookup(PIN_REQUIREMENTS, position3)
67
67
  card.technology = hash_lookup(TECHNOLOGY, position1)
68
68
  card.title = title
@@ -83,6 +83,10 @@ module Magnet
83
83
  initial, title = initial.split(".", 2) if initial
84
84
  [title, first, initial, last]
85
85
  end
86
+
87
+ def parse_pan(pan)
88
+ pan.delete(" ")
89
+ end
86
90
  end
87
91
 
88
92
  def atm_only?
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>[A-Za-z.\/ ]{2,26})\^(?<expiration>\d{4}|\^)(?<service_code>\d{3}|\^)(?<discretionary_data>[^\?]*)\?\Z/,
5
- 2 => /\A;(?<format>[A-Z])(?<pan>[0-9]{1,19})=(?<expiration>\d{4}|=)(?<service_code>\d{3}|=)(?<discretionary_data>[^\?]*)\?\Z/
4
+ 1 => /\A%(?<format>[A-Z])(?<pan>[0-9 ]{1,19})\^(?<name>[A-Za-z.\/ *]{2,26})\^(?<expiration>\d{4}|\^)(?<service_code>\d{3}|\^)(?<discretionary_data>[^\?]*)\?\Z/,
5
+ 2 => /\A;(?<format>[A-Z])(?<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)
@@ -1,3 +1,3 @@
1
1
  module Magnet
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -51,5 +51,26 @@ describe Magnet::Card do
51
51
  assert_equal "HOGAN", card.last_name
52
52
  assert_equal "DR", card.title
53
53
  end
54
+
55
+ it "should parse names with asterisks in them" do
56
+ @track_data = "%B4750550000000000^MCTEST/SYDNEY*GEE^^^?"
57
+ @attributes = { format: "B", pan: "4750550000000000", name: "MCTEST/SYDNEY*GEE", expiration: nil, service_code: nil, discretionary_data: nil }
58
+ @parser.stubs(:parse).with(@track_data).returns(@attributes)
59
+
60
+ card = Magnet::Card.parse(@track_data, @parser)
61
+
62
+ assert_equal "SYDNEY*GEE", card.first_name
63
+ assert_equal "MCTEST", card.last_name
64
+ end
65
+
66
+ it "should parse track data with spaces in the pan" do
67
+ @track_data = "%B4750550000000000^MCTEST/SYDNEY*GEE^^^?"
68
+ @attributes = { format: "B", pan: "3715 700000 00000", name: "HAMMOND/G ", expiration: nil, service_code: nil, discretionary_data: nil }
69
+ @parser.stubs(:parse).with(@track_data).returns(@attributes)
70
+
71
+ card = Magnet::Card.parse(@track_data, @parser)
72
+
73
+ assert_equal "371570000000000", card.number
74
+ end
54
75
  end
55
76
  end
@@ -71,5 +71,21 @@ describe Magnet::Parser do
71
71
  assert_equal nil, attributes[:service_code]
72
72
  assert_equal nil, attributes[:discretionary_data]
73
73
  end
74
+
75
+ it "should parse track data with asterisk in the name" do
76
+ attributes = @parser.parse("%B4750550000000000^MCTEST/SYDNEY*GEE^^^?")
77
+
78
+ assert_equal "B", attributes[:format]
79
+ assert_equal "4750550000000000", attributes[:pan]
80
+ assert_equal "MCTEST/SYDNEY*GEE", attributes[:name]
81
+ end
82
+
83
+ it "should parse track data with spaces in the pan" do
84
+ attributes = @parser.parse("%B3715 700000 00000^HAMMOND/G ^^^?")
85
+
86
+ assert_equal "B", attributes[:format]
87
+ assert_equal "3715 700000 00000", attributes[:pan]
88
+ assert_equal "HAMMOND/G ", attributes[:name]
89
+ end
74
90
  end
75
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Kadolph
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-02 00:00:00.000000000 Z
11
+ date: 2013-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -75,17 +75,17 @@ require_paths:
75
75
  - lib
76
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - ! '>='
78
+ - - '>='
79
79
  - !ruby/object:Gem::Version
80
80
  version: 1.9.2
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - ! '>='
83
+ - - '>='
84
84
  - !ruby/object:Gem::Version
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project:
88
- rubygems_version: 2.0.4
88
+ rubygems_version: 2.0.5
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: magnet is a library for decoding the track data on magnetic stripe cards.