Class: Swiper

Inherits:
Object
  • Object
show all
Defined in:
lib/swiper.rb

Defined Under Namespace

Classes: Track1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSwiper

Returns a new instance of Swiper.



13
14
15
# File 'lib/swiper.rb', line 13

def initialize
  @track1 = Swiper::Track1.new
end

Instance Attribute Details

#track1Object

Returns the value of attribute track1.



3
4
5
# File 'lib/swiper.rb', line 3

def track1
  @track1
end

Class Method Details

.can_parse?(swiped_data) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/swiper.rb', line 5

def self.can_parse?(swiped_data)
  !swiped_data.nil? && swiped_data.start_with?('%B') && !swiped_data.scan(/^%(.*)\?;(.*)\?$/)[0].nil?
end

.cant_parse?(swiped_data) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/swiper.rb', line 9

def self.cant_parse?(swiped_data)
  !can_parse?(swiped_data)
end

.parse(swiped_data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/swiper.rb', line 17

def self.parse(swiped_data)
  return false if cant_parse?(swiped_data)
    
  tracks = swiped_data.scan(/^%(.*)\?;(.*)\?$/)
  raw_track1 = tracks[0][0]
  track1_groups = raw_track1.scan(/^(.)(\d*)\^([^\/]*)\/(.*)\^(..)(..)(.*)$/)
    
  card_data = Swiper.new
  card_data.track1.raw = raw_track1
  card_data.track1.track_format = track1_groups[0][0]
  card_data.track1. = track1_groups[0][1]
  card_data.track1.cardholder_name = track1_groups[0][3].strip + ' ' + track1_groups[0][2].strip
  card_data.track1.expiration_month = track1_groups[0][5]
  card_data.track1.expiration_year = track1_groups[0][4]
  
  card_data
end