vatsim 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/vatsim/airport.rb +16 -24
- data/lib/vatsim/pilot.rb +11 -14
- data/lib/vatsim/version.rb +1 -1
- metadata +4 -4
data/lib/vatsim/airport.rb
CHANGED
@@ -7,10 +7,7 @@ module Vatsim
|
|
7
7
|
attr_reader :icao, :latitude, :longitude
|
8
8
|
|
9
9
|
# Cache of Airports already looked up to prevent searching for it again.
|
10
|
-
@@airport_cache =
|
11
|
-
|
12
|
-
# Start line for each ICAO prefix. Indexing to provide quick lookups.
|
13
|
-
@@line_numbers = {"0"=>0, "1"=>1156, "2"=>2313, "3"=>3558, "4"=>4622, "5"=>5595, "6"=>6569, "7"=>7481, "8"=>8370, "9"=>9195, "A"=>10031, "B"=>11250, "b"=>11249, "C"=>14238, "c"=>14237, "D"=>14702, "E"=>15055, "F"=>16696, "G"=>18544, "H"=>18935, "I"=>19392, "J"=>20249, "K"=>20325, "L"=>25378, "l"=>25377, "M"=>26275, "N"=>27968, "O"=>29427, "P"=>30384, "Q"=>31200, "q"=>31202, "R"=>31324, "r"=>31323, "S"=>32180, "T"=>38523, "U"=>39188, "V"=>40322, "W"=>41258, "X"=>42159, "Y"=>42387, "Z"=>44033}
|
10
|
+
@@airport_cache = nil
|
14
11
|
|
15
12
|
# Initialize Airport with colon delimited line
|
16
13
|
def initialize line
|
@@ -24,29 +21,24 @@ module Vatsim
|
|
24
21
|
}
|
25
22
|
end
|
26
23
|
|
24
|
+
|
27
25
|
# Returns Airport with given icao, or nil if it can't be found
|
28
26
|
def self.get icao
|
29
|
-
|
30
|
-
|
31
|
-
return @@airport_cache[icao] if(@@airport_cache.has_key?(icao))
|
32
|
-
|
33
|
-
line_number = 0
|
34
|
-
start_line_number = @@line_numbers[icao[0]]
|
35
|
-
start_line_number = 0 if start_line_number.nil?
|
36
|
-
|
37
|
-
Zlib::GzipReader.open(File.dirname(__FILE__) + "/airports.gz").each_line { |line|
|
38
|
-
if(line_number >= start_line_number)
|
39
|
-
if line.start_with?("#{icao}:")
|
40
|
-
values = line.split(":")
|
41
|
-
airport = Airport.new(line)
|
42
|
-
@@airport_cache.store(icao, airport) if !@@airport_cache.has_key?(icao)
|
43
|
-
break
|
44
|
-
end
|
45
|
-
end
|
46
|
-
line_number += 1
|
47
|
-
}
|
27
|
+
return self.airport_cache[icao]
|
28
|
+
end
|
48
29
|
|
49
|
-
|
30
|
+
private
|
31
|
+
|
32
|
+
# Returns Hash of airport instances
|
33
|
+
def self.airport_cache
|
34
|
+
if @@airport_cache.nil?
|
35
|
+
@@airport_cache ||= Hash.new
|
36
|
+
Zlib::GzipReader.open(File.dirname(__FILE__) + "/airports.gz").each_line { |line|
|
37
|
+
airport = Airport.new(line)
|
38
|
+
@@airport_cache.store(airport.icao, airport)
|
39
|
+
}
|
40
|
+
end
|
41
|
+
@@airport_cache
|
50
42
|
end
|
51
43
|
end
|
52
44
|
end
|
data/lib/vatsim/pilot.rb
CHANGED
@@ -3,24 +3,21 @@ module Vatsim
|
|
3
3
|
class Pilot < Client
|
4
4
|
attr_reader :callsign, :cid, :realname, :clienttype, :latitude, :longitude, :altitude, :groundspeed, :planned_aircraft, :planned_tascruise, :planned_depairport, :planned_altitude, :planned_destairport, :server, :protrevision, :rating, :transponder, :planned_revision, :planned_flighttype, :planned_deptime, :planned_actdeptime, :planned_hrsenroute, :planned_minenroute, :planned_hrsfuel, :planned_minfuel, :planned_altairport, :planned_remarks, :planned_route, :planned_depairport_lat, :planned_depairport_lon, :planned_destairport_lat, :planned_destairport_lon, :time_logon, :heading, :QNH_iHg, :QNH_Mb
|
5
5
|
|
6
|
-
def
|
7
|
-
|
8
|
-
|
6
|
+
def initialize line
|
7
|
+
super line
|
8
|
+
set_airport_locations
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
depairport = Vatsim::Airport.get(planned_depairport)
|
13
|
-
return depairport.nil? ? 0 : depairport.longitude
|
14
|
-
end
|
11
|
+
private
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def planned_destairport_lon
|
13
|
+
# Set planned_depairport/planned_destairport latitude and longitude
|
14
|
+
def set_airport_locations
|
15
|
+
depairport = Vatsim::Airport.get(planned_depairport)
|
22
16
|
destairport = Vatsim::Airport.get(planned_destairport)
|
23
|
-
|
17
|
+
@planned_depairport_lat = depairport.nil? ? 0 : depairport.latitude
|
18
|
+
@planned_depairport_lon = depairport.nil? ? 0 : depairport.longitude
|
19
|
+
@planned_destairport_lat = destairport.nil? ? 0 : destairport.latitude
|
20
|
+
@planned_destairport_lon = destairport.nil? ? 0 : destairport.longitude
|
24
21
|
end
|
25
22
|
|
26
23
|
end
|
data/lib/vatsim/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vatsim
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash: -
|
121
|
+
hash: -2755347641327459897
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
segments:
|
129
129
|
- 0
|
130
|
-
hash: -
|
130
|
+
hash: -2755347641327459897
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
133
|
rubygems_version: 1.8.24
|