vatsim 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,16 @@
1
1
  language: ruby
2
+ matrix:
3
+ allow_failures:
4
+ - rvm: jruby-18mode
5
+ - rvm: rbx-18mode
6
+ - rvm: rbx-19mode
7
+ - rvm: ree
2
8
  rvm:
3
9
  - 1.8.7
4
10
  - 1.9.2
5
11
  - 1.9.3
6
- - jruby-18mode # JRuby in 1.8 mode
12
+ - jruby-18mode
7
13
  - rbx-18mode
8
14
  - rbx-19mode
15
+ - ree
9
16
 
@@ -5,5 +5,6 @@ require 'vatsim/atc'
5
5
  require 'vatsim/prefile'
6
6
  require 'vatsim/server'
7
7
  require 'vatsim/voice_server'
8
+ require 'vatsim/airport'
8
9
  require 'vatsim/version'
9
10
 
@@ -0,0 +1,53 @@
1
+ require 'zlib'
2
+
3
+ module Vatsim
4
+ # Airport
5
+ class Airport
6
+
7
+ attr_reader :icao, :latitude, :longitude
8
+
9
+ # Cache of Airports already looked up to prevent searching for it again.
10
+ @@airport_cache = Hash.new
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}
14
+
15
+ # Initialize Airport with colon delimited line
16
+ def initialize line
17
+
18
+ attributes = [:icao, :latitude, :longitude]
19
+
20
+ line_split = line.strip.split(":")
21
+
22
+ attributes.each_with_index.map { |attribute, index|
23
+ instance_variable_set("@#{attribute}", line_split[index]) if self.respond_to?(attribute)
24
+ }
25
+ end
26
+
27
+ # Returns Airport with given icao, or nil if it can't be found
28
+ def self.get icao
29
+ airport = nil
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
+ }
48
+
49
+ airport
50
+ end
51
+ end
52
+ end
53
+
Binary file
@@ -2,6 +2,27 @@ module Vatsim
2
2
  # Connected pilot
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
+
6
+ def planned_depairport_lat
7
+ depairport = Vatsim::Airport.get(planned_depairport)
8
+ return depairport.nil? ? 0 : depairport.latitude
9
+ end
10
+
11
+ def planned_depairport_lon
12
+ depairport = Vatsim::Airport.get(planned_depairport)
13
+ return depairport.nil? ? 0 : depairport.longitude
14
+ end
15
+
16
+ def planned_destairport_lat
17
+ destairport = Vatsim::Airport.get(planned_destairport)
18
+ return destairport.nil? ? 0 : destairport.latitude
19
+ end
20
+
21
+ def planned_destairport_lon
22
+ destairport = Vatsim::Airport.get(planned_destairport)
23
+ return destairport.nil? ? 0 : destairport.longitude
24
+ end
25
+
5
26
  end
6
27
  end
7
28
 
@@ -1,4 +1,4 @@
1
1
  module Vatsim
2
- VERSION = "0.0.4" # Current gem version
2
+ VERSION = "0.0.5" # Current gem version
3
3
  end
4
4
 
@@ -6,6 +6,20 @@ describe Vatsim::VERSION do
6
6
  end
7
7
  end
8
8
 
9
+ describe Vatsim::Airport do
10
+ it "should return correct Airport" do
11
+ airport = Vatsim::Airport.get("CYYC")
12
+ airport.should_not == nil
13
+ airport.icao.should == "CYYC"
14
+ airport.latitude.should == "51.113899230957"
15
+ airport.longitude.should == "-114.019996643066"
16
+ end
17
+
18
+ it "should return nil Airport" do
19
+ Vatsim::Airport.get("NONE").should == nil
20
+ end
21
+
22
+ end
9
23
  describe Vatsim::Data do
10
24
 
11
25
  before do
@@ -70,10 +84,10 @@ describe Vatsim::Data do
70
84
  pilot.planned_altairport.should == "LTBA"
71
85
  pilot.planned_remarks.should == " /T/"
72
86
  pilot.planned_route.should == "KS LUKOS 6E8 LO 6E18 DK CRDR6 FV R11 TS R808 UUOO R368 KUBOK UA279 GR UP29 SUMOL UW100 INB UM853 BUK UW71 ILHAN"
73
- pilot.planned_depairport_lat.should == "0"
74
- pilot.planned_depairport_lon.should == "0"
75
- pilot.planned_destairport_lat.should == "0"
76
- pilot.planned_destairport_lon.should == "0"
87
+ pilot.planned_depairport_lat.should == "55.972599029541"
88
+ pilot.planned_depairport_lon.should == "37.4146003723145"
89
+ pilot.planned_destairport_lat.should == "40.1281013489"
90
+ pilot.planned_destairport_lon.should == "32.995098114"
77
91
  pilot.time_logon.should == "20120503235431"
78
92
  pilot.heading.should == "169"
79
93
  pilot.QNH_iHg.should == "29.7"
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.name = 'vatsim'
5
5
  s.version = Vatsim::VERSION
6
6
  s.summary = "Vatsim gem"
7
- s.description = "Ruby gem to retrieve Pilot/ATC online status"
7
+ s.description = "Ruby library for retrieving online status for Pilots and ATC connections on the VATSIM network (www.vatsim.net)"
8
8
  s.authors = ["Trevor Dawe"]
9
9
  s.email = 'trevor.dawe@gmail.com'
10
10
  s.files = `git ls-files`.split("\n")
@@ -14,4 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.add_development_dependency 'rspec'
15
15
  s.add_development_dependency 'webmock'
16
16
  s.add_development_dependency 'simplecov'
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
18
  end
19
+
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
4
+ version: 0.0.5
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-05-30 00:00:00.000000000 Z
12
+ date: 2012-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -75,7 +75,8 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
- description: Ruby gem to retrieve Pilot/ATC online status
78
+ description: Ruby library for retrieving online status for Pilots and ATC connections
79
+ on the VATSIM network (www.vatsim.net)
79
80
  email: trevor.dawe@gmail.com
80
81
  executables: []
81
82
  extensions: []
@@ -88,6 +89,8 @@ files:
88
89
  - README.md
89
90
  - Rakefile
90
91
  - lib/vatsim.rb
92
+ - lib/vatsim/airport.rb
93
+ - lib/vatsim/airports.gz
91
94
  - lib/vatsim/atc.rb
92
95
  - lib/vatsim/client.rb
93
96
  - lib/vatsim/data.rb
@@ -113,17 +116,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
116
  - - ! '>='
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
119
+ segments:
120
+ - 0
121
+ hash: -709285723652735854
116
122
  required_rubygems_version: !ruby/object:Gem::Requirement
117
123
  none: false
118
124
  requirements:
119
125
  - - ! '>='
120
126
  - !ruby/object:Gem::Version
121
127
  version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -709285723652735854
122
131
  requirements: []
123
132
  rubyforge_project:
124
- rubygems_version: 1.8.23
133
+ rubygems_version: 1.8.24
125
134
  signing_key:
126
135
  specification_version: 3
127
136
  summary: Vatsim gem
128
137
  test_files: []
129
- has_rdoc: