Class: TagIt::TagTracker
- Inherits:
-
Monitor
show all
- Includes:
- Observable, Timeout
- Defined in:
- lib/tag_it/tag_tracker.rb
Instance Attribute Summary
Attributes inherited from Monitor
#port
Instance Method Summary
collapse
Methods inherited from Monitor
#monitor_tags, #split_tag_data
Constructor Details
Returns a new instance of TagTracker.
9
10
11
12
|
# File 'lib/tag_it/tag_tracker.rb', line 9
def initialize(port)
super(port)
@tag_map ||= {}
end
|
Instance Method Details
33
34
35
36
37
38
39
|
# File 'lib/tag_it/tag_tracker.rb', line 33
def depart_all_tags!
@tag_map.keys.each do |tag_name|
changed
notify_observers(tag_name,0,:tag_departed)
end
@tag_map.clear
end
|
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/tag_it/tag_tracker.rb', line 41
def depart_dormant_tags!
tags_to_depart = []
@tag_map.each do |tag_name,last_time|
tags_to_depart << tag_name if((Time.now - last_time) > 8)
end
tags_to_depart.each do |tag_name|
changed
notify_observers(tag_name,0,:tag_departed)
@tag_map.delete(tag_name)
end
end
|
#flush_tag!(tag_name, strength) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/tag_it/tag_tracker.rb', line 25
def flush_tag!(tag_name,strength)
if @tag_map[tag_name].nil?
changed
notify_observers(tag_name,strength,:tag_arrived)
end
@tag_map[tag_name] = Time.now
end
|
#pulse! ⇒ Object
54
55
56
57
58
|
# File 'lib/tag_it/tag_tracker.rb', line 54
def pulse!
changed
notify_observers(@tag_map.keys.sort,0,:pulse)
@last_pulse = Time.now
end
|
#start! ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/tag_it/tag_tracker.rb', line 14
def start!
begin
monitor_tags do |tag_name,strength|
flush_tag!(tag_name,strength)
depart_dormant_tags!
end
rescue Timeout::Error
depart_all_tags!
end
end
|