Class: AIXM::Z

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
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

Returns a new instance of Z


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

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

Instance Attribute Details

#altInteger

Returns altitude or elevation value

Returns:

  • (Integer)

    altitude or elevation value


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

def alt
  @alt
end

#codeSymbol

Returns Q code - either :qfe (height in feet), :qnh (altitude in feet or :qne (altitude as flight level)

Returns:

  • (Symbol)

    Q code - either :qfe (height in feet), :qnh (altitude in feet or :qne (altitude as flight level)


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

def code
  @code
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Returns:

  • (Boolean)

See Also:

  • Object#==

80
81
82
# File 'lib/aixm/z.rb', line 80

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

#ground?Boolean

Returns whether ground level or not

Returns:

  • (Boolean)

    whether ground level or not


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

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

#hashInteger

Returns:

  • (Integer)

See Also:

  • Object#hash

87
88
89
# File 'lib/aixm/z.rb', line 87

def hash
  to_s.hash
end

#inspectString

Returns:

  • (String)

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

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

#qfe?Boolean

Examples:

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

Returns:

  • (Boolean)

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

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

#qne?Boolean

Examples:

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

Returns:

  • (Boolean)

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

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

#qnh?Boolean

Examples:

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

Returns:

  • (Boolean)

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

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

#to_sString

Returns human readable representation (e.g. “FL045” or “1350 ft QNH”)

Returns:

  • (String)

    human readable representation (e.g. “FL045” or “1350 ft QNH”)


40
41
42
# File 'lib/aixm/z.rb', line 40

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

#unitSymbol

Returns unit - either :fl (flight level) or :ft (feet)

Returns:

  • (Symbol)

    unit - either :fl (flight level) or :ft (feet)


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

def unit
  qne? ? :fl : :ft
end

#zero?Boolean

Returns whether height, elevation or altitude is zero

Returns:

  • (Boolean)

    whether height, elevation or altitude is zero


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

def_delegator :@alt, :zero?