Class: VatsimTools::CallsignRegexParser
- Inherits:
-
Object
- Object
- VatsimTools::CallsignRegexParser
- Defined in:
- lib/vatsim_online/callsign_regex_parser.rb
Constant Summary collapse
- LOCAL_DATA =
"#{Dir.tmpdir}/vatsim_online/vatsim_data.json"
Instance Method Summary collapse
-
#initialize(callsign, args = nil) ⇒ CallsignRegexParser
constructor
A new instance of CallsignRegexParser.
- #station_objects ⇒ Object
- #stations ⇒ Object
Constructor Details
#initialize(callsign, args = nil) ⇒ CallsignRegexParser
Returns a new instance of CallsignRegexParser.
14 15 16 17 18 19 20 21 |
# File 'lib/vatsim_online/callsign_regex_parser.rb', line 14 def initialize(callsign, args = nil) VatsimTools::DataDownloader.new # args.class == Hash ? @role = determine_role(args) : @role = "all" @callsign = callsign.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 |
Instance Method Details
#station_objects ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/vatsim_online/callsign_regex_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 ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/vatsim_online/callsign_regex_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 Regexp.new(cs) =~ callsign[0...cs.length] # && 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 |