class Airport

Attributes

code[RW]

Airport's ICAO code.

name[RW]

Airport's full name.

variance[RW]

Airport's magnetic variance from true north.

Public Class Methods

new(**kvargs) click to toggle source

Params: :code, :name, :variance

# File lib/vrc-tools/airport.rb, line 16
def initialize(**kvargs)
  @code     = kvargs.fetch :code, ''
  @name     = kvargs.fetch :name, ''
  @variance = kvargs.fetch :variance, 17.0 # TODO: Detect this intelligently.
end

Public Instance Methods

discover_name() click to toggle source

Discover the airport's full name based on ICAO code.

# File lib/vrc-tools/airport.rb, line 24
def discover_name
  uri = URI "http://www.airnav.com/airport/#{@code.to_s.downcase}"
  response = Net::HTTP.get uri
  
  l = response.scan %r{(?i:<title>)(?:AirNav:\s*\w*\s*-\s*)?(.*)(?i:</title>)}
  
  raise NameDiscoveryError, "Could not discover name for #{@code.to_s.upcase}"        unless l.count > 0
    
  @name = l.flatten.first
end
discover_variance() click to toggle source

Discover the airport's magnetic variance based on ICAO code.

# File lib/vrc-tools/airport.rb, line 38
def discover_variance
end
magnetic_heading_from(departure) click to toggle source

Calculate the magnetic heading from the specified airport. Takes an ICAO code or Airport object.

# File lib/vrc-tools/airport.rb, line 68
def magnetic_heading_from(departure)
  true_to_magnetic true_heading_from(departure)
end
magnetic_heading_to(arrival) click to toggle source

Calculate the magnetic heading to the specified airport. Takes an ICAO code or Airport object.

# File lib/vrc-tools/airport.rb, line 62
def magnetic_heading_to(arrival)
  true_to_magnetic true_heading_to(arrival)
end
magnetic_to_true(heading) click to toggle source

Convert a magnetic heading to true based on the airport's magnetic variance.

# File lib/vrc-tools/airport.rb, line 80
def magnetic_to_true(heading)
  heading + @variance
end
to_s() click to toggle source

Print the Airport ICAO code. Allows the object to act as a direct replacement for string input.

# File lib/vrc-tools/airport.rb, line 86
def to_s
  @code
end
true_heading_from(departure) click to toggle source

Calculate the true heading from the specified airport. Takes an ICAO code or Airport object.

# File lib/vrc-tools/airport.rb, line 56
def true_heading_from(departure)
  360.0 - true_heading_to(departure)
end
true_heading_to(arrival) click to toggle source

Calculate the true heading to the specified airport. Takes an ICAO code or Airport object.

# File lib/vrc-tools/airport.rb, line 43
def true_heading_to(arrival)
  heading_uri = "http://www6.landings.com/cgi-bin/nph-dist_apt?airport1=#{@code.downcase}&airport2=#{arrival.to_s.strip.downcase}"
  response = Net::HTTP.get URI heading_uri
  r = response.scan /(?:heading:)\s*([\d\.]+)\s+/
  
  raise HeadingError, "Heading from #{@code.upcase} to @arrival.to_s.upcase not found."        unless r.count > 0
  
  true_hdg = r.flatten.first.to_f
end
true_to_magnetic(heading) click to toggle source

Convert a true heading to magnetic based on the airport's magnetic variance.

# File lib/vrc-tools/airport.rb, line 74
def true_to_magnetic(heading)
  heading - @variance
end