Class: AIXM::Z

Inherits:
Object
  • Object
show all
Defined in:
lib/aixm/z.rb

Overview

Height, elevation or altitude

Shortcuts:

  • AIXM::GROUND - surface expressed as “0 ft QFE”

  • AIXM::UNLIMITED - no upper limit expressed as “FL 999”

Examples:

AIXM.z(1000, :qfe)   # height (ft): 1000 ft above ground
AIXM.z(2000, :qnh)   # elevation or altitude (ft): 2000 ft above mean sea level
AIXM.z(45, :qne)     # altitude: flight level 45

Constant Summary collapse

CODES =
i(qfe qnh qne).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(alt, code) ⇒ Z


24
25
26
# File 'lib/aixm/z.rb', line 24

def initialize(alt, code)
  self.alt, self.code = alt, code
end

Instance Attribute Details

#altInteger


19
20
21
# File 'lib/aixm/z.rb', line 19

def alt
  @alt
end

#codeSymbol


22
23
24
# File 'lib/aixm/z.rb', line 22

def code
  @code
end

Instance Method Details

#==(other) ⇒ Boolean


50
51
52
# File 'lib/aixm/z.rb', line 50

def ==(other)
  other.is_a?(self.class) && alt == other.alt && code == other.code
end

#ground?Boolean


68
69
70
# File 'lib/aixm/z.rb', line 68

def ground?
  qfe? && @alt == 0
end

#inspectString


29
30
31
# File 'lib/aixm/z.rb', line 29

def inspect
  %Q(#<#{self.class} #{to_s}>)
end

#qfe?Boolean

Examples:

z = AIXM.z(123, :qnh)
z.qnh?   # => true
z.qfe?   # => false

63
64
65
# File 'lib/aixm/z.rb', line 63

CODES.each do |code|
  define_method(:"#{code}?") { @code == code }
end

#qne?Boolean

Examples:

z = AIXM.z(123, :qnh)
z.qnh?   # => true
z.qfe?   # => false

63
64
65
# File 'lib/aixm/z.rb', line 63

CODES.each do |code|
  define_method(:"#{code}?") { @code == code }
end

#qnh?Boolean

Examples:

z = AIXM.z(123, :qnh)
z.qnh?   # => true
z.qfe?   # => false

63
64
65
# File 'lib/aixm/z.rb', line 63

CODES.each do |code|
  define_method(:"#{code}?") { @code == code }
end

#to_sString


34
35
36
# File 'lib/aixm/z.rb', line 34

def to_s
  qne? ? "FL%03i" % alt : [alt, unit, code.upcase].join(' ')
end

#unitSymbol


73
74
75
# File 'lib/aixm/z.rb', line 73

def unit
  qne? ? :fl : :ft
end