Class: AIXM::Z

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

Methods included from Concerns::HashEquality

#eql?, #hash

Constructor Details

#initialize(alt, code) ⇒ Z

See the overview for examples.



46
47
48
# File 'lib/aixm/z.rb', line 46

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

Instance Attribute Details

#altInteger #alt=(value) ⇒ Object

Altitude or elevation value.

Overloads:

  • #altInteger

    Returns:

    • (Integer)
  • #alt=(value) ⇒ Object

    Parameters:

    • value (Integer)


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

def alt
  @alt
end

#codeSymbol #code=(value) ⇒ Object

Q code

Overloads:

  • #codeSymbol

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

    Returns:

    • (Symbol)

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

  • #code=(value) ⇒ Object

    Parameters:

    • value (Symbol)

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



43
44
45
# File 'lib/aixm/z.rb', line 43

def code
  @code
end

Instance Method Details

#==(other) ⇒ Object

See Also:

  • Object#==


101
102
103
# File 'lib/aixm/z.rb', line 101

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

#ground?Boolean

Whether ground level

Returns:

  • (Boolean)


89
90
91
# File 'lib/aixm/z.rb', line 89

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

#inspectString

Returns:

  • (String)


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

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

#qfe?Boolean

Whether QFE, QNH or QNE.

Examples:

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

Returns:

  • (Boolean)


82
83
84
# File 'lib/aixm/z.rb', line 82

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

#qne?Boolean

Whether QFE, QNH or QNE.

Examples:

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

Returns:

  • (Boolean)


82
83
84
# File 'lib/aixm/z.rb', line 82

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

#qnh?Boolean

Whether QFE, QNH or QNE.

Examples:

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

Returns:

  • (Boolean)


82
83
84
# File 'lib/aixm/z.rb', line 82

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”)



56
57
58
# File 'lib/aixm/z.rb', line 56

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

#unitSymbol

Unit

Returns:

  • (Symbol)

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



96
97
98
# File 'lib/aixm/z.rb', line 96

def unit
  qne? ? :fl : :ft
end

#zero?Boolean

Returns:

  • (Boolean)


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

def_delegator :@alt, :zero?