class VatsimTools::CallsignParser

Constants

LOCAL_DATA

Public Class Methods

new(callsign, args = nil) click to toggle source
# File lib/vatsim_online/callsign_parser.rb, line 14
def initialize(callsign, args = nil)
  VatsimTools::DataDownloader.new
  # args.class == Hash ? @role = determine_role(args) : @role = "all"
  @callsign = callsign.upcase.split(',').each {|s| s.strip!}
  # @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

Public Instance Methods

station_objects() click to toggle source
# File lib/vatsim_online/callsign_parser.rb, line 49
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() click to toggle source

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

# File lib/vatsim_online/callsign_parser.rb, line 31
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']
    @callsign.each do |cs|
      matching_stations << station if callsign[0...cs.length] == cs # && client == "ATC") unless @role == "pilot"
      # stations << row if (origin[0...icao.length] == icao || destination[0...icao.length] == icao) unless @role == "atc"
    end
  end
  matching_stations
end