vatsim_online_redux 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +120 -0
- data/CONTRIBUTING.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE +23 -0
- data/README.md +478 -0
- data/Rakefile +7 -0
- data/lib/vatsim_online/callsign_parser.rb +54 -0
- data/lib/vatsim_online/data_downloader.rb +134 -0
- data/lib/vatsim_online/station.rb +92 -0
- data/lib/vatsim_online/station_parser.rb +77 -0
- data/lib/vatsim_online/version.rb +3 -0
- data/lib/vatsim_online.rb +24 -0
- data/spec/callsign_parser_spec.rb +29 -0
- data/spec/callsign_parser_spec_helper.rb +10 -0
- data/spec/data_downloader_spec.rb +105 -0
- data/spec/data_downloader_spec_helper.rb +8 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/station_parser_spec.rb +161 -0
- data/spec/station_parser_spec_helper.rb +10 -0
- data/spec/vatsim_data.txt +515 -0
- data/spec/vatsim_online_spec.rb +157 -0
- data/spec/vatsim_online_spec_helper.rb +10 -0
- data/vatsim_online_redux.gemspec +25 -0
- metadata +172 -0
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'vatsim_online'
|
2
|
+
require 'station_parser_spec_helper.rb'
|
3
|
+
|
4
|
+
describe VatsimTools::StationParser do
|
5
|
+
|
6
|
+
target = VatsimTools::StationParser
|
7
|
+
|
8
|
+
describe "determine role" do
|
9
|
+
it "should return a role" do
|
10
|
+
args = {:pilots => true, :atc => true}
|
11
|
+
target.new("loww", args).determine_role(args).should eq("all")
|
12
|
+
args = {:pilots => true, :atc => false}
|
13
|
+
target.new("loww", args).determine_role(args).should eq("pilot")
|
14
|
+
args = {:pilots => false, :atc => true}
|
15
|
+
target.new("loww", args).determine_role(args).should eq("atc")
|
16
|
+
args = {:pilots => false, :atc => false}
|
17
|
+
target.new("loww", args).determine_role(args).should eq("all")
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should initialize the instance var" do
|
21
|
+
args = {:pilots => true, :atc => true}
|
22
|
+
target.new("loww", args).role.should eq("all")
|
23
|
+
args = {:pilots => false, :atc => true}
|
24
|
+
target.new("loww", args).role.should eq("atc")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "excluded list" do
|
29
|
+
it "should not interfere if missing" do
|
30
|
+
args = {:exclude => "loww"}
|
31
|
+
target.new("loww", args).role.should eq("all")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "stations" do
|
36
|
+
args = {:pilots => true, :atc => true}
|
37
|
+
it "should return an expected result" do
|
38
|
+
gem_data_file
|
39
|
+
icao = "WMKK"
|
40
|
+
target.new(icao, args).stations.first[0].should eq("WMKK_APP")
|
41
|
+
target.new(icao, args).stations.class.should eq(Array)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should distinguish roles" do
|
45
|
+
gem_data_file
|
46
|
+
icao = "WMKK"
|
47
|
+
args = {:pilots => false, :atc => true}
|
48
|
+
target.new(icao, args).stations.first[0].should eq("WMKK_APP")
|
49
|
+
target.new(icao, args).stations.class.should eq(Array)
|
50
|
+
args = {:pilots => true, :atc => false}
|
51
|
+
target.new(icao, args).stations.length.should be(0)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should combine all stations" do
|
55
|
+
gem_data_file
|
56
|
+
icao = "LO"
|
57
|
+
args = {:pilots => true, :atc => true}
|
58
|
+
target.new(icao, args).stations.first[0].should eq("AMZ1105")
|
59
|
+
target.new(icao, args).stations.last[0].should eq("OS601")
|
60
|
+
target.new(icao, args).stations.last[11].should eq("LOWW")
|
61
|
+
target.new(icao, args).stations.last[13].should eq("UUDD")
|
62
|
+
target.new(icao, args).stations.class.should eq(Array)
|
63
|
+
target.new(icao, args).stations.count.should eq(12)
|
64
|
+
args = {:pilots => false, :atc => true}
|
65
|
+
target.new(icao, args).stations.count.should eq(0)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "station_objects" do
|
70
|
+
it "should return an array of Station objects" do
|
71
|
+
gem_data_file
|
72
|
+
icao = "LO"
|
73
|
+
target.new(icao).station_objects.class.should eq(Array)
|
74
|
+
target.new(icao).station_objects.size.should eq(12)
|
75
|
+
args = {:pilots => false}
|
76
|
+
target.new(icao, args).station_objects.size.should eq(0)
|
77
|
+
args = {:atc => false}
|
78
|
+
target.new(icao, args).station_objects.size.should eq(12)
|
79
|
+
target.new(icao, args).station_objects.first.class.should eq(VatsimTools::Station)
|
80
|
+
target.new(icao, args).station_objects.first.callsign.should eq("AMZ1105")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "sorted_station_objects" do
|
85
|
+
it "should return an hash with arrays of Station objects" do
|
86
|
+
gem_data_file
|
87
|
+
icao = "WM"
|
88
|
+
target.new(icao).sorted_station_objects.class.should eq(Hash)
|
89
|
+
target.new(icao).sorted_station_objects.size.should eq(4)
|
90
|
+
target.new(icao).sorted_station_objects[:atc].class.should eq(Array)
|
91
|
+
target.new(icao).sorted_station_objects[:pilots].class.should eq(Array)
|
92
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(0)
|
93
|
+
target.new(icao).sorted_station_objects[:atc].size.should eq(4)
|
94
|
+
target.new(icao).sorted_station_objects[:atc].first.class.should eq(VatsimTools::Station)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should handle roles" do
|
98
|
+
gem_data_file
|
99
|
+
icao = "WM"
|
100
|
+
atc = {:pilots => false}
|
101
|
+
pilots = {:atc => false}
|
102
|
+
target.new(icao, atc).sorted_station_objects.class.should eq(Hash)
|
103
|
+
target.new(icao, atc).sorted_station_objects.size.should eq(4)
|
104
|
+
target.new(icao, atc).sorted_station_objects[:atc].class.should eq(Array)
|
105
|
+
target.new(icao, atc).sorted_station_objects[:pilots].class.should eq(Array)
|
106
|
+
|
107
|
+
target.new(icao, atc).sorted_station_objects[:pilots].size.should eq(0)
|
108
|
+
target.new(icao, atc).sorted_station_objects[:atc].size.should eq(4)
|
109
|
+
target.new(icao, pilots).sorted_station_objects[:atc].size.should eq(0)
|
110
|
+
target.new(icao, pilots).sorted_station_objects[:pilots].size.should eq(0)
|
111
|
+
target.new(icao, atc).sorted_station_objects[:atc].first.callsign.should eq("WMKK_APP")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should recognize arrivals and departures" do
|
115
|
+
gem_data_file
|
116
|
+
icao = "LO"
|
117
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(12)
|
118
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(target.new(icao).sorted_station_objects[:arrivals].size + target.new(icao).sorted_station_objects[:departures].size)
|
119
|
+
target.new(icao).sorted_station_objects[:arrivals].size.should eq(6)
|
120
|
+
target.new(icao).sorted_station_objects[:departures].size.should eq(6)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should recognize exclusions" do
|
124
|
+
gem_data_file
|
125
|
+
icao = "LB"
|
126
|
+
target.new(icao).sorted_station_objects[:atc].size.should eq(4)
|
127
|
+
args = {:exclude => "LBGO"}
|
128
|
+
target.new(icao, args).excluded.should eq("LBGO")
|
129
|
+
target.new(icao, args).excluded.length.should eq(4)
|
130
|
+
target.new(icao, args).sorted_station_objects[:atc].size.should eq(3)
|
131
|
+
args = {:exclude => "LBSF"}
|
132
|
+
target.new(icao, args).sorted_station_objects[:atc].size.should eq(2)
|
133
|
+
args = {:exclude => "lbsf"}
|
134
|
+
target.new(icao, args).sorted_station_objects[:atc].size.should eq(2)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should support multiple icaos" do
|
138
|
+
gem_data_file
|
139
|
+
icao = "LB"
|
140
|
+
target.new(icao).sorted_station_objects[:atc].size.should eq(4)
|
141
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(2)
|
142
|
+
icao = "LO"
|
143
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(12)
|
144
|
+
target.new(icao).sorted_station_objects[:atc].size.should eq(0)
|
145
|
+
gem_data_file
|
146
|
+
icao = "LO,LB"
|
147
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(14)
|
148
|
+
target.new(icao).sorted_station_objects[:atc].size.should eq(4)
|
149
|
+
icao = "LO, LB"
|
150
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(14)
|
151
|
+
target.new(icao).sorted_station_objects[:atc].size.should eq(4)
|
152
|
+
icao = "LO , LB"
|
153
|
+
target.new(icao).sorted_station_objects[:pilots].size.should eq(14)
|
154
|
+
target.new(icao).sorted_station_objects[:arrivals].size.should eq(7)
|
155
|
+
target.new(icao).sorted_station_objects[:departures].size.should eq(7)
|
156
|
+
target.new(icao).sorted_station_objects[:atc].size.should eq(4)
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
def gem_data_file
|
2
|
+
path = File.realpath("spec/vatsim_data.txt")
|
3
|
+
data_file = File.open(path, :encoding => 'iso-8859-15')
|
4
|
+
gem_data = data_file.read
|
5
|
+
data_file.close
|
6
|
+
data = Tempfile.new('vatsim_data', :encoding => 'iso-8859-15')
|
7
|
+
data.write(gem_data.gsub(/["]/, '\s').force_encoding('iso-8859-15'))
|
8
|
+
data.close
|
9
|
+
File.rename data.path, "#{Dir.tmpdir}/vatsim_data.txt"
|
10
|
+
end
|