Class: VatsimTools::StationParser
- Inherits:
-
Object
- Object
- VatsimTools::StationParser
- Defined in:
- lib/vatsim_online/station_parser.rb
Constant Summary collapse
- LOCAL_DATA =
"#{Dir.tmpdir}/vatsim_online/vatsim_data.json"
Instance Method Summary collapse
- #determine_role(args) ⇒ Object
-
#initialize(icao, args = nil) ⇒ StationParser
constructor
A new instance of StationParser.
- #sorted_station_objects ⇒ Object
- #station_objects ⇒ Object
- #stations ⇒ Object
Constructor Details
#initialize(icao, args = nil) ⇒ StationParser
Returns a new instance of StationParser.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vatsim_online/station_parser.rb', line 14 def initialize(icao, args = nil) VatsimTools::DataDownloader.new args.class == Hash ? @role = determine_role(args) : @role = "all" if icao == "ALL" @icao = nil else @icao = icao.upcase.split(',').each { |s| s.strip! } end @excluded = args[:exclude].upcase if args && args[:exclude] @gcmap_width = args[:gcmap_width] if args && args[:gcmap_width] @gcmap_height = args[:gcmap_height] if args && args[:gcmap_height] end |
Instance Method Details
#determine_role(args) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/vatsim_online/station_parser.rb', line 27 def determine_role(args) args[:atc] == false ? role = "pilot" : role = "all" args[:pilots] == false ? role = "atc" : role = role role = "all" if args[:pilots] == false && args[:atc] == false role end |
#sorted_station_objects ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/vatsim_online/station_parser.rb', line 69 def sorted_station_objects atc = []; pilots = []; arrivals = []; departures = [] station_objects.each { |sobj| sobj.role == "controller" ? atc << sobj : pilots << sobj } if @icao @icao.each do |icao| pilots.each do |pilot| departures << pilot if pilot.origin[0...icao.length] == icao arrivals << pilot if pilot.destination[0...icao.length] == icao end end end atc.delete_if { |a| @excluded && a.callsign[0...@excluded.length] == @excluded } { :atc => atc, :pilots => pilots, :arrivals => arrivals, :departures => departures } end |
#station_objects ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/vatsim_online/station_parser.rb', line 60 def station_objects station_objects = [] args = {} args[:gcmap_width] = @gcmap_width if @gcmap_width args[:gcmap_height] = @gcmap_height if @gcmap_height stations.each { |station| station_objects << VatsimTools::Station.new(station, args) } station_objects end |
#stations ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vatsim_online/station_parser.rb', line 34 def stations matching_stations = [] raw_data = File.read(LOCAL_DATA) data = JSON.parse(raw_data) pilots = data['pilots'].each { |p| p['role'] = 'pilot' } controllers = data['controllers'].each { |p| p['role'] = 'controller' } atis = data['atis'].each { |p| p['role'] = 'atis' } stations = pilots + controllers + atis stations.each do |station| callsign = station['callsign'] destination = station['flight_plan']['arrival'] rescue '' origin = station['flight_plan']['departure'] rescue '' client = station['role'] unless @icao matching_stations << station if (client == "controller") unless @role == "pilot" matching_stations << station if (client == "pilot") unless @role == "atc" else @icao.each do |icao| matching_stations << station if (callsign[0...icao.length] == icao && client == "controller") unless @role == "pilot" matching_stations << station if (origin[0...icao.length] == icao || destination[0...icao.length] == icao) unless @role == "atc" end end end matching_stations end |