Class: Swiper
- Inherits:
-
Object
- Object
- Swiper
- Defined in:
- lib/swiper.rb
Defined Under Namespace
Classes: Track1
Instance Attribute Summary collapse
-
#track1 ⇒ Object
Returns the value of attribute track1.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Swiper
constructor
A new instance of Swiper.
Constructor Details
Instance Attribute Details
#track1 ⇒ Object
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
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
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.primary_account_number = 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 |