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_written ⇒ Object
Returns the value of attribute events_written.
Instance Method Summary collapse
- #clear ⇒ Object
-
#delete_object(object_id) ⇒ Object
Process a delete event for an object.
-
#initialize ⇒ EventQueue
constructor
A new instance of EventQueue.
-
#set_property(property:, value:) ⇒ Object
Set a property.
- #shift ⇒ Object
- #size ⇒ Object
-
#update_object(event) ⇒ Object
Process an update event for an object.
-
#update_time(time) ⇒ Object
Process a time update event.
Constructor Details
#initialize ⇒ EventQueue
Returns a new instance of EventQueue.
11 12 13 14 |
# File 'lib/tac_scribe/event_queue.rb', line 11 def initialize @events = Queue.new self.events_written = 0 end |
Instance Attribute Details
#events_written ⇒ Object
Returns the value of attribute events_written.
9 10 11 |
# File 'lib/tac_scribe/event_queue.rb', line 9 def events_written @events_written end |
Instance Method Details
#clear ⇒ Object
16 17 18 |
# File 'lib/tac_scribe/event_queue.rb', line 16 def clear @events.clear end |
#delete_object(object_id) ⇒ Object
Process a delete event for an object
54 55 56 57 |
# File 'lib/tac_scribe/event_queue.rb', line 54 def delete_object(object_id) self.events_written += 1 @events << { type: :delete_object, object_id: object_id } end |
#set_property(property:, value:) ⇒ Object
Set a property
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tac_scribe/event_queue.rb', line 71 def set_property(property:, value:) case property when 'ReferenceLatitude' @events << { type: :set_latitude, value: BigDecimal(value) } when 'ReferenceLongitude' @events << { type: :set_longitude, value: BigDecimal(value) } when 'ReferenceTime' @reference_time = @time = Time.parse(value) end end |
#shift ⇒ Object
24 25 26 |
# File 'lib/tac_scribe/event_queue.rb', line 24 def shift @events.shift end |
#size ⇒ Object
20 21 22 |
# File 'lib/tac_scribe/event_queue.rb', line 20 def size @events.size 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
45 46 47 48 |
# File 'lib/tac_scribe/event_queue.rb', line 45 def update_object(event) self.events_written += 1 @events << { type: :update_object, event: event, time: @time } end |
#update_time(time) ⇒ Object
Process a time update event
63 64 65 |
# File 'lib/tac_scribe/event_queue.rb', line 63 def update_time(time) @time = @reference_time + time end |