Class: ADSB::Database
- Inherits:
-
Object
- Object
- ADSB::Database
- Defined in:
- lib/adsb2kml/database.rb
Instance Attribute Summary collapse
-
#icon_url ⇒ Object
Returns the value of attribute icon_url.
Instance Method Summary collapse
- #expire_after(time = 120) ⇒ Object
-
#initialize(name = "ADSB") ⇒ Database
constructor
A new instance of Database.
- #to_cons ⇒ Object
- #to_kml ⇒ Object
- #update(airplane) ⇒ Object
- #update_t(airplane) ⇒ Object
Constructor Details
#initialize(name = "ADSB") ⇒ Database
Returns a new instance of Database.
8 9 10 11 12 |
# File 'lib/adsb2kml/database.rb', line 8 def initialize name = "ADSB" @name = name @airplanes = {} @icon_url = "/plane_icon.png" end |
Instance Attribute Details
#icon_url ⇒ Object
Returns the value of attribute icon_url.
6 7 8 |
# File 'lib/adsb2kml/database.rb', line 6 def icon_url @icon_url end |
Instance Method Details
#expire_after(time = 120) ⇒ Object
56 57 58 59 |
# File 'lib/adsb2kml/database.rb', line 56 def expire_after time = 120 @time_expire = time spawn_thread :watch_expire end |
#to_cons ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/adsb2kml/database.rb', line 44 def to_cons to_return = sprintf $STRING_FORMAT, "Address", "Latitude", "Longitude", "Altitude", "Speed", "Last Heard", "Time Diff", "Track" @airplanes.each do |address, air| to_return += air.to_cons end return to_return end |
#to_kml ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/adsb2kml/database.rb', line 30 def to_kml kml = KMLFile.new folder = KML::Folder.new( :name => @name ) @airplanes.each do |address, airplane| folder.features << airplane.icon(@icon_url) folder.features << airplane.placemark end kml.objects << folder return kml end |
#update(airplane) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/adsb2kml/database.rb', line 15 def update airplane if ( @airplanes.has_key? airplane.address ) then @airplanes[airplane.address].merge_with airplane else @airplanes[airplane.address] = airplane end end |
#update_t(airplane) ⇒ Object
23 24 25 26 27 |
# File 'lib/adsb2kml/database.rb', line 23 def update_t airplane Thread.new do update airplane end end |