Class: ATCTools::FlightPlan
- Inherits:
-
Object
- Object
- ATCTools::FlightPlan
- Defined in:
- lib/atc-tools/flight_plan.rb
Instance Attribute Summary collapse
-
#aircraft ⇒ Object
Aircraft type/info.
-
#alternate ⇒ Object
Alternate airport.
-
#arrive ⇒ Object
Arrival airport.
-
#callsign ⇒ Object
Aircraft callsign.
-
#cruise ⇒ Object
Cruising altitude.
-
#depart ⇒ Object
Departure airport.
-
#remarks ⇒ Object
Additional remarks/notes.
-
#route ⇒ Object
Flight route.
-
#rules ⇒ Object
Flight rules.
-
#scratchpad ⇒ Object
Scratch pad.
-
#squawk ⇒ Object
Squawk code.
Instance Method Summary collapse
-
#altitude_valid? ⇒ Boolean
Validate the cruising altitude given the arrival airport and flight rules.
-
#heading ⇒ Object
Magnetic heading from the departure to arrival airport.
-
#initialize(**kvargs) ⇒ FlightPlan
constructor
Params: :callsign, :aircraft, :rules, :depart, :arrive, :alternate, :cruse, :squawk, :route, :remarks, :scratchpad – See instance variables for descriptions.
-
#to_s ⇒ Object
Returns a human-readable version of the flight plan.
-
#validate ⇒ Object
Validate the flight plan.
Constructor Details
#initialize(**kvargs) ⇒ FlightPlan
Params:
:callsign, :aircraft, :rules, :depart, :arrive, :alternate, :cruse,
:squawk, :route, :remarks, :scratchpad
-- See instance variables for descriptions.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |
Instance Attribute Details
#aircraft ⇒ Object
Aircraft type/info.
9 10 11 |
# File 'lib/atc-tools/flight_plan.rb', line 9 def aircraft @aircraft end |
#alternate ⇒ Object
Alternate airport.
17 18 19 |
# File 'lib/atc-tools/flight_plan.rb', line 17 def alternate @alternate end |
#arrive ⇒ Object
Arrival airport.
15 16 17 |
# File 'lib/atc-tools/flight_plan.rb', line 15 def arrive @arrive end |
#callsign ⇒ Object
Aircraft callsign.
7 8 9 |
# File 'lib/atc-tools/flight_plan.rb', line 7 def callsign @callsign end |
#cruise ⇒ Object
Cruising altitude.
19 20 21 |
# File 'lib/atc-tools/flight_plan.rb', line 19 def cruise @cruise end |
#depart ⇒ Object
Departure airport.
13 14 15 |
# File 'lib/atc-tools/flight_plan.rb', line 13 def depart @depart end |
#remarks ⇒ Object
Additional remarks/notes.
25 26 27 |
# File 'lib/atc-tools/flight_plan.rb', line 25 def remarks @remarks end |
#route ⇒ Object
Flight route.
23 24 25 |
# File 'lib/atc-tools/flight_plan.rb', line 23 def route @route end |
#rules ⇒ Object
Flight rules.
11 12 13 |
# File 'lib/atc-tools/flight_plan.rb', line 11 def rules @rules end |
#scratchpad ⇒ Object
Scratch pad.
27 28 29 |
# File 'lib/atc-tools/flight_plan.rb', line 27 def scratchpad @scratchpad end |
#squawk ⇒ Object
Squawk code.
21 22 23 |
# File 'lib/atc-tools/flight_plan.rb', line 21 def squawk @squawk end |
Instance Method Details
#altitude_valid? ⇒ Boolean
Validate the cruising altitude given the arrival airport and flight rules.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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. len = 0 len = 1 if @cruise.to_s.length >= 5 cruise_stripped = @cruise.to_s[0..len].to_i is_north_east = (@heading < 180 || @heading >= 360) rules = @rules.upcase.to_sym case rules when :IFR above_fl410 = @cruise.to_i / 100 > 410 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 ⇒ Object
Magnetic heading from the departure to arrival airport.
50 51 52 53 |
# 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 ⇒ Object
Returns a human-readable version of the flight plan.
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/atc-tools/flight_plan.rb', line 113 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 ⇒ Object
Validate the flight plan.
109 110 |
# File 'lib/atc-tools/flight_plan.rb', line 109 def validate end |