class ATCTools::FlightPlan

Attributes

aircraft[RW]

Aircraft type/info.

alternate[RW]

Alternate airport.

arrive[RW]

Arrival airport.

callsign[RW]

Aircraft callsign.

cruise[RW]

Cruising altitude.

depart[RW]

Departure airport.

remarks[RW]

Additional remarks/notes.

route[RW]

Flight route.

rules[RW]

Flight rules.

scratchpad[RW]

Scratch pad.

squawk[RW]

Squawk code.

Public Class Methods

new(**kvargs) click to toggle source

Params:

:callsign, :aircraft, :rules, :depart, :arrive, :alternate, :cruse,
:squawk, :route, :remarks, :scratchpad
-- See instance variables for descriptions.
# File lib/atc-tools/flight_plan.rb, line 33
def initialize(**kvargs)
  @callsign   = kvargs.fetch :callsign,  ''
  @aircraft   = kvargs.fetch :aircraft,  ATCTools::Aircraft.new
  @rules      = kvargs.fetch :rules,     ''
  @depart     = kvargs.fetch :depart,    ATCTools::Airport.new
  @arrive     = kvargs.fetch :arrive,    ATCTools::Airport.new
  @alternate  = kvargs.fetch :alternate, ATCTools::Airport.new
  @cruise     = kvargs.fetch :cruise,    0
  @squawk     = kvargs.fetch :squawk,    '0000'
  @route      = kvargs.fetch :route,     ''
  @remarks    = kvargs.fetch :remarks,   ''
  @scratchpad = kvargs.fetch :scratchpad, ''
  
  @heading    = nil
end

Public Instance Methods

altitude_valid?() click to toggle source

Validate the cruising altitude given the arrival airport and flight rules.

# File lib/atc-tools/flight_plan.rb, line 57
def altitude_valid?
  # TODO: This can cause a bug if the destination airport is changed
  #       after the heading is calculated. Although a new FlightPlan
  #       object should be created in this case, the problem should
  #       still be fixed.
  @heading = @depart.magnetic_heading_to @arrive unless @heading
  
  # Strip the zeros off of the altitude for even/odd comparison.
  cruise_stripped = @cruise.to_s.gsub(/0/, '').to_i
  is_north_east = (@heading < 180 || @heading >= 360)
  
  rules = @rules.upcase.to_sym
  case rules
  when :IFR
    above_fl410 = cruise_stripped > 41
    
    if above_fl410
      east_alt = [45, 49, 53, 57, 61]
      west_alt = [43, 47, 51, 55, 59]
      
      east_valid = (is_north_east && east_alt.include?(cruise_stripped))
      west_valid = ((not is_north_east) && west_alt.include?(cruise_stripped))
      
      return true if east_valid || west_valid
    else
      return true if
        (is_north_east && cruise_stripped.odd?) ||
        ((not is_north_east) && cruise_stripped.even?)
    end
      
  when :VFR
  end
  
  false
end
heading() click to toggle source

Magnetic heading from the departure to arrival airport.

# File lib/atc-tools/flight_plan.rb, line 50
def heading
  altitude_valid? unless @heading # Run the validator to populate @heading.
  @heading
end
to_s() click to toggle source

Returns a human-readable version of the flight plan.

# File lib/atc-tools/flight_plan.rb, line 98
    def to_s
      data = <<EOS
Callsign:   #{@callsign}
A/C Type:   #{@aircraft}
Rules:      #{@rules}

Depart:     #{@depart}
Arrive:     #{@arrive} :: #{@arrive.name}
Alternate:  #{@alternate}

Route:      #{@route}

Cruise:     #{@cruise}
Scratchpad: #{@scratchpad}
Squawk:     #{@squawk}

Remarks:    #{@remarks}
EOS
    end
validate() click to toggle source

Validate the flight plan.

# File lib/atc-tools/flight_plan.rb, line 94
def validate
end