Class: CTAPI::APDU

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

Overview

APDU (Application Protocol Data Unit) that is sent to/received from the cardterminal. This is the parent class of Command and Response.

Direct Known Subclasses

Command, Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ APDU

An APDU object is generated from the String data.



398
399
400
# File 'lib/ctapi.rb', line 398

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

This is the data string.



403
404
405
# File 'lib/ctapi.rb', line 403

def data
  @data
end

Instance Method Details

#[](*args) ⇒ Object

Access data string by indices.



406
# File 'lib/ctapi.rb', line 406

def [](*args) @data[*args] end

#inspectObject

We use Ruby’s inspect representation to inspect the data.



409
410
411
# File 'lib/ctapi.rb', line 409

def inspect
  @data.inspect
end

#to_sObject

To display the data, a string of the form ‘12:23:a4’ is built.



414
415
416
# File 'lib/ctapi.rb', line 414

def to_s
  @data.unpack('C*').map { |x| sprintf("%02x", x) }.join(':')
end