lib/vatsim/data.rb
def parse
      download_files

      parsing_clients = false
      parsing_prefile = false
      parsing_general = false
      parsing_servers = false
      parsing_voice_servers = false

      File.open(DATA_FILE_PATH, 'r:ascii-8bit').each { |line|

        if line.start_with? ";"
          parsing_clients = false
          parsing_prefile = false
          parsing_general = false
          parsing_servers = false
          parsing_voice_servers = false
        elsif parsing_clients
          clienttype = line.split(":")[3]
          if clienttype.eql? "PILOT"
            @pilots << Pilot.new(line)
          elsif clienttype.eql? "ATC"
            @atc << ATC.new(line)
          end
        elsif parsing_prefile
          @prefiles << Prefile.new(line)
        elsif parsing_general
          line_split = line.split("=")
          @general[line_split[0].strip.downcase.gsub(" ", "_")] = line_split[1].strip
        elsif parsing_servers
          @servers << Server.new(line)
        elsif parsing_voice_servers
          @voice_servers << VoiceServer.new(line) if line.length > 2 # ignore last, empty line for voice server that contains 2 characters
        end

        parsing_clients = true if line.start_with? "!CLIENTS:"
        parsing_prefile = true if line.start_with? "!PREFILE:"
        parsing_general = true if line.start_with? "!GENERAL:"
        parsing_servers = true if line.start_with? "!SERVERS:"
        parsing_voice_servers = true if line.start_with? "!VOICE SERVERS:"
      }
    end
def parse
      download_files

      parsing_clients = false
      parsing_prefile = false
      parsing_general = false
      parsing_servers = false
      parsing_voice_servers = false

      File.open(DATA_FILE_PATH, 'r:ascii-8bit').each { |line|

        if line.start_with? ";"
          parsing_clients = false
          parsing_prefile = false
          parsing_general = false
          parsing_servers = false
          parsing_voice_servers = false
        elsif parsing_clients
          clienttype = line.split(":")[3]
          if clienttype.eql? "PILOT"
            @pilots << Pilot.new(line)
          elsif clienttype.eql? "ATC"
            @atc << ATC.new(line)
          end
        elsif parsing_prefile
          @prefiles << Prefile.new(line)
        elsif parsing_general
          line_split = line.split("=")
          @general[line_split[0].strip.downcase.gsub(" ", "_")] = line_split[1].strip
        elsif parsing_servers
          @servers << Server.new(line)
        elsif parsing_voice_servers
          @voice_servers << VoiceServer.new(line) if line.length > 2 # ignore last, empty line for voice server that contains 2 characters
        end

        parsing_clients = true if line.start_with? "!CLIENTS:"
        parsing_prefile = true if line.start_with? "!PREFILE:"
        parsing_general = true if line.start_with? "!GENERAL:"
        parsing_servers = true if line.start_with? "!SERVERS:"
        parsing_voice_servers = true if line.start_with? "!VOICE SERVERS:"
      }
    end
def parse download_files parsing_clients = false parsing_prefile = false parsing_general = false parsing_servers = false parsing_voice_servers = false File . open ( DATA_FILE_PATH , 'r:ascii-8bit' ) . each { | line | if line . start_with? ";" parsing_clients = false parsing_prefile = false parsing_general = false parsing_servers = false parsing_voice_servers = false elsif parsing_clients clienttype = line . split ( ":" ) [ 3 ] if clienttype . eql? "PILOT" @pilots << Pilot . new ( line ) elsif clienttype . eql? "ATC" @atc << ATC . new ( line ) end elsif parsing_prefile @prefiles << Prefile . new ( line ) elsif parsing_general line_split = line . split ( "=" ) @general [ line_split [ 0 ] . strip . downcase . gsub ( " " , "_" ) ] = line_split [ 1 ] . strip elsif parsing_servers @servers << Server . new ( line ) elsif parsing_voice_servers @voice_servers << VoiceServer . new ( line ) if line . length > 2 # ignore last, empty line for voice server that contains 2 characters end parsing_clients = true if line . start_with? "!CLIENTS:" parsing_prefile = true if line . start_with? "!PREFILE:" parsing_general = true if line . start_with? "!GENERAL:" parsing_servers = true if line . start_with? "!SERVERS:" parsing_voice_servers = true if line . start_with? "!VOICE SERVERS:" } end
Parse the vatsim data file and store output as necessary
Parse the vatsim data file and store output as necessary