vatsim 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -0
- data/lib/vatsim.rb +0 -1
- data/lib/vatsim/client.rb +0 -2
- data/lib/vatsim/data.rb +21 -31
- data/lib/vatsim/prefile.rb +0 -2
- data/lib/vatsim/version.rb +1 -1
- metadata +3 -3
- data/lib/vatsim/general.rb +0 -6
data/README.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# vatsim.rb
|
2
|
+
vatsim.rb is a Ruby library for retrieving online status for Pilots and ATC connections on the [VATSIM] network.
|
3
|
+
|
4
|
+
[VATSIM]: http://www.vatsim.net
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
gem install vatsim
|
8
|
+
|
9
|
+
## Documentation
|
10
|
+
[http://rdoc.info/gems/vatsim][documentation]
|
11
|
+
|
12
|
+
[documentation]: http://rdoc.info/gems/vatsim
|
data/lib/vatsim.rb
CHANGED
data/lib/vatsim/client.rb
CHANGED
@@ -5,7 +5,6 @@ module Vatsim
|
|
5
5
|
|
6
6
|
# Initialize Client with colon delimited line from vatsim-data.txt format
|
7
7
|
def initialize line
|
8
|
-
|
9
8
|
attributes = [:callsign, :cid, :realname, :clienttype, :frequency, :latitude, :longitude, :altitude, :groundspeed, :planned_aircraft, :planned_tascruise, :planned_depairport, :planned_altitude, :planned_destairport, :server, :protrevision, :rating, :transponder, :facilitytype, :visualrange, :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, :atis_message, :time_last_atis_received, :time_logon, :heading, :QNH_iHg, :QNH_Mb]
|
10
9
|
|
11
10
|
line_split = line.split(":")
|
@@ -13,7 +12,6 @@ module Vatsim
|
|
13
12
|
attributes.each_with_index.map { |attribute, index|
|
14
13
|
instance_variable_set("@#{attribute}", line_split[index]) if self.respond_to?(attribute)
|
15
14
|
}
|
16
|
-
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
data/lib/vatsim/data.rb
CHANGED
@@ -28,7 +28,6 @@ module Vatsim
|
|
28
28
|
end
|
29
29
|
|
30
30
|
parse
|
31
|
-
|
32
31
|
end
|
33
32
|
|
34
33
|
# Returns all connected Pilots
|
@@ -53,40 +52,35 @@ module Vatsim
|
|
53
52
|
|
54
53
|
# Parse the vatsim data file and store output as necessary
|
55
54
|
def parse
|
55
|
+
download_files if @refresh_files
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
parsing_clients = false
|
62
|
-
parsing_prefile = false
|
63
|
-
parsing_general = false
|
57
|
+
parsing_clients = false
|
58
|
+
parsing_prefile = false
|
59
|
+
parsing_general = false
|
64
60
|
|
65
|
-
|
61
|
+
File.open(@data_file_path, 'r:ascii-8bit').each { |line|
|
66
62
|
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
parsing_clients = false if line.start_with? ";"
|
64
|
+
parsing_prefile = false if line.start_with? ";"
|
65
|
+
parsing_general = false if line.start_with? ";"
|
70
66
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
67
|
+
if parsing_clients
|
68
|
+
@clients << Client.new(line)
|
69
|
+
elsif parsing_prefile
|
70
|
+
@prefiles << Prefile.new(line)
|
71
|
+
elsif parsing_general
|
72
|
+
line_split = line.split("=")
|
73
|
+
@general[line_split[0].strip.downcase.gsub(" ", "_")] = line_split[1].strip
|
74
|
+
end
|
79
75
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
76
|
+
parsing_clients = true if line.start_with? "!CLIENTS:"
|
77
|
+
parsing_prefile = true if line.start_with? "!PREFILE:"
|
78
|
+
parsing_general = true if line.start_with? "!GENERAL:"
|
79
|
+
}
|
85
80
|
end
|
86
81
|
|
87
82
|
# Initialize the system by downloading status and vatsim data files
|
88
83
|
def download_files
|
89
|
-
|
90
84
|
if !File.exists?(@status_file_path) or File.mtime(@status_file_path) < Time.now - STATUS_DOWNLOAD_INTERVAL
|
91
85
|
download_to_file STATUS_URL, @status_file_path
|
92
86
|
end
|
@@ -94,7 +88,6 @@ module Vatsim
|
|
94
88
|
if !File.exists?(@data_file_path ) or File.mtime(@data_file_path ) < Time.now - DATA_DOWNLOAD_INTERVAL
|
95
89
|
download_to_file random_data_url, @data_file_path
|
96
90
|
end
|
97
|
-
|
98
91
|
end
|
99
92
|
|
100
93
|
# Download a url to a file path
|
@@ -103,18 +96,16 @@ module Vatsim
|
|
103
96
|
|
104
97
|
File.new(file, File::CREAT)
|
105
98
|
|
106
|
-
|
99
|
+
Net::HTTP.start(url.host) { |http|
|
107
100
|
resp = http.get(url.path)
|
108
101
|
open(file, "wb") { |file|
|
109
102
|
file.write(resp.body)
|
110
103
|
}
|
111
104
|
}
|
112
|
-
|
113
105
|
end
|
114
106
|
|
115
107
|
# Return random vatsim data url from status file
|
116
108
|
def random_data_url
|
117
|
-
|
118
109
|
url0s = Array.new
|
119
110
|
file = File.open(@status_file_path)
|
120
111
|
file.each {|line|
|
@@ -123,7 +114,6 @@ module Vatsim
|
|
123
114
|
end
|
124
115
|
}
|
125
116
|
return url0s[rand(url0s.length)]
|
126
|
-
|
127
117
|
end
|
128
118
|
end
|
129
119
|
end
|
data/lib/vatsim/prefile.rb
CHANGED
@@ -4,7 +4,6 @@ module Vatsim
|
|
4
4
|
attr_reader :callsign, :cid, :realname, :clienttype, :frequency, :latitude, :longitude, :altitude, :groundspeed, :planned_aircraft, :planned_tascruise, :planned_depairport, :planned_altitude, :planned_destairport, :server, :protrevision, :rating, :transponder, :facilitytype, :visualrange, :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, :atis_message, :time_last_atis_received, :time_logon, :heading, :QNH_iHg, :QNH_Mb
|
5
5
|
|
6
6
|
def initialize line
|
7
|
-
|
8
7
|
attributes = [:callsign, :cid, :realname, :clienttype, :frequency, :latitude, :longitude, :altitude, :groundspeed, :planned_aircraft, :planned_tascruise, :planned_depairport, :planned_altitude, :planned_destairport, :server, :protrevision, :rating, :transponder, :facilitytype, :visualrange, :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, :atis_message, :time_last_atis_received, :time_logon, :heading, :QNH_iHg, :QNH_Mb]
|
9
8
|
|
10
9
|
line_split = line.split(":")
|
@@ -12,7 +11,6 @@ module Vatsim
|
|
12
11
|
attributes.each_with_index.map { |attribute, index|
|
13
12
|
instance_variable_set("@#{attribute}", line_split[index]) if self.respond_to?(attribute)
|
14
13
|
}
|
15
|
-
|
16
14
|
end
|
17
15
|
end
|
18
16
|
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.3
|
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-
|
12
|
+
date: 2012-05-19 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Ruby gem to retrieve Pilot/ATC online status
|
15
15
|
email: trevor.dawe@gmail.com
|
@@ -19,11 +19,11 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- .gitignore
|
21
21
|
- .rspec
|
22
|
+
- README.md
|
22
23
|
- Rakefile
|
23
24
|
- lib/vatsim.rb
|
24
25
|
- lib/vatsim/client.rb
|
25
26
|
- lib/vatsim/data.rb
|
26
|
-
- lib/vatsim/general.rb
|
27
27
|
- lib/vatsim/prefile.rb
|
28
28
|
- lib/vatsim/version.rb
|
29
29
|
- spec/spec_helper.rb
|