Class: Magnet::Card

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

Constant Summary collapse

ALLOWED_SERVICES =
{
  0..1 => :no_restrictions,
  2 => :goods_and_services_only,
  3 => :atm_only,
  4 => :cash_only,
  5 => :goods_and_services_only,
  6 => :no_restrictions,
  7 => :goods_and_services_only
}.freeze
AUTHORIZATION_PROCESSING =
{
  0 => :normal,
  2 => :by_issuer,
  4 => :by_issuer_unless_explicit_agreement
}.freeze
FORMAT =
{
  "A" => :reserved,
  "B" => :bank,
  "C".."M" => :reserved,
  "N".."Z" => :available
}.freeze
INTERCHANGE =
{
  1..2 => :international,
  5..6 => :national,
  7 => :private,
  9 => :test
}.freeze
PIN_REQUIREMENTS =
{
  0 => :pin_required,
  3 => :pin_required,
  5 => :pin_required,
  6..7 => :prompt_for_pin_if_ped_present
}.freeze
TECHNOLOGY =
{
  2 => :integrated_circuit_card,
  6 => :integrated_circuit_card
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allowed_servicesObject

Returns the value of attribute allowed_services.



45
46
47
# File 'lib/magnet/card.rb', line 45

def allowed_services
  @allowed_services
end

#authorization_processingObject

Returns the value of attribute authorization_processing.



45
46
47
# File 'lib/magnet/card.rb', line 45

def authorization_processing
  @authorization_processing
end

#discretionary_dataObject

Returns the value of attribute discretionary_data.



45
46
47
# File 'lib/magnet/card.rb', line 45

def discretionary_data
  @discretionary_data
end

#expiration_monthObject

Returns the value of attribute expiration_month.



45
46
47
# File 'lib/magnet/card.rb', line 45

def expiration_month
  @expiration_month
end

#expiration_yearObject

Returns the value of attribute expiration_year.



45
46
47
# File 'lib/magnet/card.rb', line 45

def expiration_year
  @expiration_year
end

#first_nameObject

Returns the value of attribute first_name.



45
46
47
# File 'lib/magnet/card.rb', line 45

def first_name
  @first_name
end

#formatObject

Returns the value of attribute format.



45
46
47
# File 'lib/magnet/card.rb', line 45

def format
  @format
end

#initialObject

Returns the value of attribute initial.



45
46
47
# File 'lib/magnet/card.rb', line 45

def initial
  @initial
end

#interchangeObject

Returns the value of attribute interchange.



45
46
47
# File 'lib/magnet/card.rb', line 45

def interchange
  @interchange
end

#last_nameObject

Returns the value of attribute last_name.



45
46
47
# File 'lib/magnet/card.rb', line 45

def last_name
  @last_name
end

#numberObject

Returns the value of attribute number.



45
46
47
# File 'lib/magnet/card.rb', line 45

def number
  @number
end

#pin_requirementsObject

Returns the value of attribute pin_requirements.



45
46
47
# File 'lib/magnet/card.rb', line 45

def pin_requirements
  @pin_requirements
end

#technologyObject

Returns the value of attribute technology.



45
46
47
# File 'lib/magnet/card.rb', line 45

def technology
  @technology
end

#titleObject

Returns the value of attribute title.



45
46
47
# File 'lib/magnet/card.rb', line 45

def title
  @title
end

Class Method Details

.parse(track_data, parser = Parser.new(:auto)) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/magnet/card.rb', line 48

def parse(track_data, parser = Parser.new(:auto))
  attributes = parser.parse(track_data)
  position1, position2, position3 = (attributes[:service_code] || "").scan(/\d/).map(&:to_i)
  year, month = (attributes[:expiration] || "").scan(/\d\d/).map(&:to_i)
  title, first_name, initial, last_name = parse_name(attributes[:name].rstrip) if attributes[:name]

  card = new
  card.allowed_services = hash_lookup(ALLOWED_SERVICES, position3)
  card.authorization_processing = hash_lookup(AUTHORIZATION_PROCESSING, position2)
  card.discretionary_data = attributes[:discretionary_data]
  card.expiration_month = month
  card.expiration_year = year
  card.first_name = first_name
  card.format = hash_lookup(FORMAT, attributes[:format])
  card.initial = initial
  card.interchange = hash_lookup(INTERCHANGE, position1)
  card.last_name = last_name
  card.number = parse_pan(attributes[:pan])
  card.pin_requirements = hash_lookup(PIN_REQUIREMENTS, position3)
  card.technology = hash_lookup(TECHNOLOGY, position1)
  card.title = title
  card
end

Instance Method Details

#atm_only?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/magnet/card.rb', line 92

def atm_only?
  allowed_services == :atm_only
end

#cash_only?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/magnet/card.rb', line 96

def cash_only?
  allowed_services == :cash_only
end

#goods_and_services_only?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/magnet/card.rb', line 100

def goods_and_services_only?
  allowed_services == :goods_and_services_only
end

#integrated_circuit_card?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/magnet/card.rb', line 104

def integrated_circuit_card?
  technology == :integrated_circuit_card
end

#international?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/magnet/card.rb', line 108

def international?
  interchange == :international
end

#national?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/magnet/card.rb', line 112

def national?
  interchange == :national
end

#no_service_restrictions?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/magnet/card.rb', line 116

def no_service_restrictions?
  allowed_services = :no_restrictions
end

#pin_required?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/magnet/card.rb', line 120

def pin_required?
  pin_requirements == :pin_required
end

#private?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/magnet/card.rb', line 124

def private?
  interchange == :private
end

#process_by_issuer?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/magnet/card.rb', line 128

def process_by_issuer?
  authorization_processing == :by_issuer
end

#process_by_issuer_unless_explicit_agreement?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/magnet/card.rb', line 132

def process_by_issuer_unless_explicit_agreement?
  authorization_processing == :by_issuer_unless_explicit_agreement
end

#process_normally?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/magnet/card.rb', line 136

def process_normally?
  authorization_processing == :normal
end

#prompt_for_pin_if_ped_present?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/magnet/card.rb', line 140

def prompt_for_pin_if_ped_present?
  pin_requirements == :prompt_for_pin_if_ped_present
end

#test?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/magnet/card.rb', line 144

def test?
  interchange == :test
end