swiper 0.0.1
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/lib/swiper.rb +43 -0
- metadata +54 -0
data/lib/swiper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
class Swiper
|
2
|
+
|
3
|
+
attr_accessor :track1
|
4
|
+
|
5
|
+
def self.can_parse?(swiped_data)
|
6
|
+
!swiped_data.nil? && swiped_data.start_with?('%B')
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.cant_parse?(swiped_data)
|
10
|
+
!can_parse?(swiped_data)
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@track1 = Swiper::Track1.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse(swiped_data)
|
18
|
+
return false if cant_parse?(swiped_data)
|
19
|
+
|
20
|
+
tracks = swiped_data.scan(/^%(.*)\?;(.*)\?$/)
|
21
|
+
raw_track1 = tracks[0][0]
|
22
|
+
track1_groups = raw_track1.scan(/^(.)(\d*)\^([^\/]*)\/(.*)\^(..)(..)(.*)$/)
|
23
|
+
|
24
|
+
card_data = Swiper.new
|
25
|
+
card_data.track1.raw = raw_track1
|
26
|
+
card_data.track1.track_format = track1_groups[0][0]
|
27
|
+
card_data.track1.primary_account_number = track1_groups[0][1]
|
28
|
+
card_data.track1.cardholder_name = track1_groups[0][3].strip + ' ' + track1_groups[0][2].strip
|
29
|
+
card_data.track1.expiration_month = track1_groups[0][5]
|
30
|
+
card_data.track1.expiration_year = track1_groups[0][4]
|
31
|
+
|
32
|
+
card_data
|
33
|
+
end
|
34
|
+
|
35
|
+
class Track1
|
36
|
+
attr_accessor :raw,
|
37
|
+
:track_format,
|
38
|
+
:primary_account_number,
|
39
|
+
:cardholder_name,
|
40
|
+
:expiration_month,
|
41
|
+
:expiration_year
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: swiper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Gary Moore
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-01-12 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Parses Track 1 magstripe data
|
17
|
+
email: gary.moore@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/swiper.rb
|
26
|
+
homepage: http://github.com/fracturedatlas/swiper
|
27
|
+
licenses: []
|
28
|
+
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
requirements: []
|
47
|
+
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.6
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Parses Track 1 magstripe data
|
53
|
+
test_files: []
|
54
|
+
|