Class: TacScribe::EventQueue
- Inherits:
-
TacviewClient::BaseProcessor
- Object
- TacviewClient::BaseProcessor
- TacScribe::EventQueue
- Defined in:
- lib/tac_scribe/event_queue.rb
Overview
Processes the events emitted by the Ruby Tacview Client
Instance Attribute Summary collapse
-
#events ⇒ Object
Returns the value of attribute events.
-
#reference_latitude ⇒ Object
Returns the value of attribute reference_latitude.
-
#reference_longitude ⇒ Object
Returns the value of attribute reference_longitude.
Instance Method Summary collapse
-
#delete_object(object_id) ⇒ Object
Process a delete event for an object.
-
#initialize(verbose_logging:) ⇒ EventQueue
constructor
A new instance of EventQueue.
-
#set_property(property:, value:) ⇒ Object
Set a property.
-
#update_object(event) ⇒ Object
Process an update event for an object.
-
#update_time(time) ⇒ Object
Process a time update event.
Constructor Details
#initialize(verbose_logging:) ⇒ EventQueue
Returns a new instance of EventQueue.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tac_scribe/event_queue.rb', line 11 def initialize(verbose_logging:) @verbose_logging = verbose_logging @events = Queue.new @event_count = 0 return unless verbose_logging == true Thread.new do loop do puts "#{Time.now.strftime("%FT%T")} - Queue Size: #{@events.size} \t Events Processed: #{@event_count}" @event_count = 0 sleep 1 end end end |
Instance Attribute Details
#events ⇒ Object
Returns the value of attribute events.
9 10 11 |
# File 'lib/tac_scribe/event_queue.rb', line 9 def events @events end |
#reference_latitude ⇒ Object
Returns the value of attribute reference_latitude.
9 10 11 |
# File 'lib/tac_scribe/event_queue.rb', line 9 def reference_latitude @reference_latitude end |
#reference_longitude ⇒ Object
Returns the value of attribute reference_longitude.
9 10 11 |
# File 'lib/tac_scribe/event_queue.rb', line 9 def reference_longitude @reference_longitude end |
Instance Method Details
#delete_object(object_id) ⇒ Object
Process a delete event for an object
53 54 55 56 |
# File 'lib/tac_scribe/event_queue.rb', line 53 def delete_object(object_id) @event_count += 1 events << { type: :delete_object, object_id: object_id } end |
#set_property(property:, value:) ⇒ Object
Set a property
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tac_scribe/event_queue.rb', line 70 def set_property(property:, value:) case property when 'ReferenceLatitude' self.reference_latitude = BigDecimal(value) when 'ReferenceLongitude' self.reference_longitude = BigDecimal(value) when 'ReferenceTime' @reference_time = @time = Time.parse(value) end end |
#update_object(event) ⇒ Object
Process an update event for an object
On the first appearance of the object there are usually more fields including pilot names, object type etc.
For existing objects these events are almost always lat/lon/alt updates only
44 45 46 47 |
# File 'lib/tac_scribe/event_queue.rb', line 44 def update_object(event) @event_count += 1 events << { type: :update_object, event: event, time: @time } end |
#update_time(time) ⇒ Object
Process a time update event
62 63 64 |
# File 'lib/tac_scribe/event_queue.rb', line 62 def update_time(time) @time = @reference_time + time end |