Class: NFC::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-nfc/tags/tag.rb

Direct Known Subclasses

IsoDep::Tag, Mifare::Tag

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, reader) ⇒ Tag

Returns a new instance of Tag.



3
4
5
6
7
# File 'lib/ruby-nfc/tags/tag.rb', line 3

def initialize(target, reader)
	@target = target
	@reader = reader
	@processed = false
end

Class Method Details

.match?(target) ⇒ Boolean

Matches any NFC tag

Returns:

  • (Boolean)


43
44
45
# File 'lib/ruby-nfc/tags/tag.rb', line 43

def self.match?(target)
	true
end

Instance Method Details

#connect(&block) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/ruby-nfc/tags/tag.rb', line 9

def connect(&block)
	if block_given?
		begin
			self.instance_eval(&block)
		ensure
			disconnect
		end
	end
end

#disconnectObject



27
# File 'lib/ruby-nfc/tags/tag.rb', line 27

def disconnect; end

#processed!Object



19
20
21
# File 'lib/ruby-nfc/tags/tag.rb', line 19

def processed!
	@target.processed!
end

#processed?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby-nfc/tags/tag.rb', line 23

def processed?
	@target.processed?
end

#to_sObject



38
39
40
# File 'lib/ruby-nfc/tags/tag.rb', line 38

def to_s
	uid_hex
end

#uidObject



29
30
31
32
# File 'lib/ruby-nfc/tags/tag.rb', line 29

def uid
	uid_size = @target[:nti][:nai][:szUidLen]
	@target[:nti][:nai][:abtUid].to_s[0...uid_size]
end

#uid_hexObject



34
35
36
# File 'lib/ruby-nfc/tags/tag.rb', line 34

def uid_hex
	uid.unpack('H*').pop
end