magnet 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
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=
@@ -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)
@@ -20,7 +20,7 @@ module Magnet
20
20
  attributes[:name] = m[:name]
21
21
  attributes[:expiration] = m[:expiration] == "^" ? nil : m[:expiration]
22
22
  attributes[:service_code] = m[:service_code] == "^" ? nil : m[:service_code]
23
- attributes[:discretionary_data] = m[:discretionary_data]
23
+ attributes[:discretionary_data] = m[:discretionary_data] == "" ? nil : m[:discretionary_data]
24
24
  return attributes
25
25
  end
26
26
  end
@@ -1,3 +1,3 @@
1
1
  module Magnet
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -38,5 +38,38 @@ describe Magnet::Parser do
38
38
  assert_equal "321", attributes[:service_code]
39
39
  assert_equal "0000000725000000", attributes[:discretionary_data]
40
40
  end
41
+
42
+ it "should parse without discretionary data" do
43
+ attributes = @parser.parse("%B5452300551227189^HOGAN/PAUL ^0804321?")
44
+
45
+ assert_equal "B", attributes[:format]
46
+ assert_equal "5452300551227189", attributes[:pan]
47
+ assert_equal "HOGAN/PAUL ", attributes[:name]
48
+ assert_equal "0804", attributes[:expiration]
49
+ assert_equal "321", attributes[:service_code]
50
+ assert_equal nil, attributes[:discretionary_data]
51
+ end
52
+
53
+ it "should parse with ^ as the expiration" do
54
+ attributes = @parser.parse("%B5452300551227189^HOGAN/PAUL ^^321?")
55
+
56
+ assert_equal "B", attributes[:format]
57
+ assert_equal "5452300551227189", attributes[:pan]
58
+ assert_equal "HOGAN/PAUL ", attributes[:name]
59
+ assert_equal nil, attributes[:expiration]
60
+ assert_equal "321", attributes[:service_code]
61
+ assert_equal nil, attributes[:discretionary_data]
62
+ end
63
+
64
+ it "should parse with ^ as the service code" do
65
+ attributes = @parser.parse("%B5452300551227189^HOGAN/PAUL ^0804^?")
66
+
67
+ assert_equal "B", attributes[:format]
68
+ assert_equal "5452300551227189", attributes[:pan]
69
+ assert_equal "HOGAN/PAUL ", attributes[:name]
70
+ assert_equal "0804", attributes[:expiration]
71
+ assert_equal nil, attributes[:service_code]
72
+ assert_equal nil, attributes[:discretionary_data]
73
+ end
41
74
  end
42
75
  end
metadata CHANGED
@@ -1,36 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magnet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Samuel Kadolph
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-18 00:00:00.000000000 Z
11
+ date: 2013-08-02 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.6
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.6
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: mocha
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
31
  - - ~>
20
32
  - !ruby/object:Gem::Version
21
- version: 0.13.2
33
+ version: 0.14.0
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
38
  - - ~>
28
39
  - !ruby/object:Gem::Version
29
- version: 0.13.2
40
+ version: 0.14.0
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
45
  - - ~>
36
46
  - !ruby/object:Gem::Version
@@ -38,7 +48,6 @@ dependencies:
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
52
  - - ~>
44
53
  - !ruby/object:Gem::Version
@@ -59,27 +68,26 @@ files:
59
68
  - test/magnet/parser_test.rb
60
69
  homepage: http://samuelkadolph.github.com/magnet/
61
70
  licenses: []
71
+ metadata: {}
62
72
  post_install_message:
63
73
  rdoc_options: []
64
74
  require_paths:
65
75
  - lib
66
76
  required_ruby_version: !ruby/object:Gem::Requirement
67
- none: false
68
77
  requirements:
69
78
  - - ! '>='
70
79
  - !ruby/object:Gem::Version
71
80
  version: 1.9.2
72
81
  required_rubygems_version: !ruby/object:Gem::Requirement
73
- none: false
74
82
  requirements:
75
83
  - - ! '>='
76
84
  - !ruby/object:Gem::Version
77
85
  version: '0'
78
86
  requirements: []
79
87
  rubyforge_project:
80
- rubygems_version: 1.8.25
88
+ rubygems_version: 2.0.4
81
89
  signing_key:
82
- specification_version: 3
90
+ specification_version: 4
83
91
  summary: magnet is a library for decoding the track data on magnetic stripe cards.
84
92
  test_files:
85
93
  - test/magnet/card_test.rb