Class: TacScribe::EventQueue

Inherits:
TacviewClient::BaseProcessor
  • Object
show all
Defined in:
lib/tac_scribe/event_queue.rb

Overview

Processes the events emitted by the Ruby Tacview Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeEventQueue



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_writtenObject

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

#clearObject



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

#shiftObject



24
25
26
# File 'lib/tac_scribe/event_queue.rb', line 24

def shift
  @events.shift
end

#sizeObject



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

Options Hash (event):

  • :object_id (String)

    The hexadecimal format object ID.

  • :latitude (BigDecimal)

    The object latitude in WGS 84 format.

  • :longitude (BigDecimal)

    The object latitude in WGS 84 format.

  • :altitude (BigDecimal)

    The object altitude above sea level in meters to 1 decimal place.



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