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)


41
42
43
# File 'lib/ruby-nfc/tags/tag.rb', line 41

def self.match?(target)
	true
end

Instance Method Details

#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

#select(&block) ⇒ Object



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

def select(&block)
	if block_given?
		begin
			self.instance_eval(&block)
		ensure
			deselect
		end
	end
end

#to_sObject



36
37
38
# File 'lib/ruby-nfc/tags/tag.rb', line 36

def to_s
	uid_hex
end

#uidObject



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

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

#uid_hexObject



32
33
34
# File 'lib/ruby-nfc/tags/tag.rb', line 32

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