Class: APDU::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-nfc/apdu/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.

Raises:



5
6
7
8
9
10
11
12
# File 'lib/ruby-nfc/apdu/response.rb', line 5

def initialize(response)
	resp_8bit = response.dup
	resp_8bit.force_encoding('ASCII-8BIT')

	raise APDU::Error, "Response must be at least 2-bytes long" if resp_8bit.size < 2

	@response = resp_8bit
end

Instance Method Details

#[](index) ⇒ Object



44
45
46
# File 'lib/ruby-nfc/apdu/response.rb', line 44

def [](index)
	@response[index]
end

#dataObject



36
37
38
# File 'lib/ruby-nfc/apdu/response.rb', line 36

def data
	@response[0...-2]
end

#raise_errno!Object

Public: Raises APDU::Errno if self.sw is not equal 0x9000

Raises:



15
16
17
18
# File 'lib/ruby-nfc/apdu/response.rb', line 15

def raise_errno!
	raise APDU::Errno.new(sw) if sw != 0x9000
	self
end

#swObject

Public: Return Status Word of an APDU response. Status Word is a two-byte result code



22
23
24
# File 'lib/ruby-nfc/apdu/response.rb', line 22

def sw
	@response[-2, 2].unpack('n').pop
end

#sw1Object

Public: Return high byte of Status Word



27
28
29
# File 'lib/ruby-nfc/apdu/response.rb', line 27

def sw1
	@response[-2, 1].unpack('C').pop
end

#sw2Object

Public: Return low byte of Status Word



32
33
34
# File 'lib/ruby-nfc/apdu/response.rb', line 32

def sw2
	@response[-1,1].unpack('C').pop
end

#to_sObject



40
41
42
# File 'lib/ruby-nfc/apdu/response.rb', line 40

def to_s
	@response.unpack('H*').pop.upcase
end