Class: Iso7813::Track2

Inherits:
Object
  • Object
show all
Includes:
Iso7812::CardNumber
Defined in:
lib/iso7813/track2.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#expiration_dateObject

Returns the value of attribute expiration_date.



10
11
12
# File 'lib/iso7813/track2.rb', line 10

def expiration_date
  @expiration_date
end

#panObject

Returns the value of attribute pan.



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

def pan
  @pan
end

#service_codeObject

Returns the value of attribute service_code.



11
12
13
# File 'lib/iso7813/track2.rb', line 11

def service_code
  @service_code
end

Class Method Details

.generate(fields = {}, include_lrc_and_sentinel = false) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/iso7813/track2.rb', line 47

def self.generate(fields = {}, include_lrc_and_sentinel = false)

  track2 = Track2.new
  track2.pan = fields[:pan]
  track2.expiration_date = fields[:expiration_date]
  track2.service_code = fields[:service_code]

  track2.track(include_lrc_and_sentinel)
end

Instance Method Details

#ddObject



25
26
27
# File 'lib/iso7813/track2.rb', line 25

def dd
  "#{stx}#{pan}#{fs}#{ed}#{sc}".length.to_s
end

#edObject



17
18
19
# File 'lib/iso7813/track2.rb', line 17

def ed
  expiration_date || "="
end

#etxObject



29
30
31
# File 'lib/iso7813/track2.rb', line 29

def etx
  "?"
end

#fsObject



33
34
35
# File 'lib/iso7813/track2.rb', line 33

def fs
  '='
end

#lrc(_track) ⇒ Object



37
38
39
# File 'lib/iso7813/track2.rb', line 37

def lrc(_track)
  raise 'The track printer should do that, not the track generation software (parity)'
end

#scObject



21
22
23
# File 'lib/iso7813/track2.rb', line 21

def sc
  service_code || "="
end

#stxObject



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

def stx
  ';'
end

#track(include_lrc_and_sentinel = false) ⇒ Object



41
42
43
44
45
# File 'lib/iso7813/track2.rb', line 41

def track(include_lrc_and_sentinel = false)
  _track = "#{stx}#{pan}#{fs}#{ed}#{sc}#{dd}"
  _track << "#{etx}#{lrc(_track)}" if include_lrc_and_sentinel
  _track
end