Class: NOTAM::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/notam/message.rb

Overview

NOTAM messages are plain text and consist of several ordered items:

WDDDD/DD ...   <- Header (mandatory)
Q) ...         <- Q item: context (mandatory)
A) ...         <- A item: locations (mandatory)
B) ...         <- B item: effective from (mandatory)
C) ...         <- C item: effective until (optional)
D) ...         <- D item: timesheets (optional, may contain newlines)
E) ...         <- E item: description (mandatory, may contain newlines)
F) ...         <- F item: upper limit (optional)
G) ...         <- G item: lower limit (optional)
CREATED: ...   <- Footer (optional)
SOURCE: ...    <- Footer (optional)

Furthermore, oversized NOTAM may be split into several partial messages which contain with PART n OF n and END PART n OF n markers. This is an unofficial extension and therefore the markers may be found in different places such as on the A item, on the E item or even somewhere in between.

Constant Summary collapse

UNSUPPORTED_FORMATS =
%r(
  \A
  ![A-Z]{3,5} |                       # USA: NOTAM (D), FDC etc
  \w{3}\s\w{3}\s\([OU]\) |            # USA: (O) and (U) NOTAM
  \w{3}\s[A-Z]\d{4}/\d{2}\sMILITARY   # USA: military
)xi.freeze
PART_RE =
%r(
  (?:END\s+)?PART\s+(?<part_index>\d+)\s+OF\s+(?<part_index_max>\d+)
)xim.freeze
FINGERPRINTS =
%w[Q) A) B) C) D) E) F) G) CREATED: SOURCE:].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Message

Returns a new instance of Message.



53
54
55
56
57
58
59
60
# File 'lib/notam/message.rb', line 53

def initialize(text)
  fail(NOTAM::ParserError, "unsupported format") unless self.class.supported_format? text
  @text, @items, @data = text, [], {}
  itemize(departition(@text)).each do |raw_item|
    item = NOTAM::Item.new(raw_item, data: @data).parse.merge
    @items << item
  end
end

Instance Attribute Details

#dataHash (readonly)

Parsed NOTAM message payload

Returns:

  • (Hash)


51
52
53
# File 'lib/notam/message.rb', line 51

def data
  @data
end

#itemsArray<NOTAM::Item> (readonly)

NOTAM item objects

Returns:



46
47
48
# File 'lib/notam/message.rb', line 46

def items
  @items
end

#textString (readonly)

Raw NOTAM text message

Returns:

  • (String)


41
42
43
# File 'lib/notam/message.rb', line 41

def text
  @text
end

Class Method Details

.parse(text) ⇒ NOTAM::Message

Parse the given raw NOTAM text message to create a new NOTAM::Message object.

Returns:



90
91
92
93
94
95
# File 'lib/notam/message.rb', line 90

def parse(text)
  allocate.instance_eval do
    initialize(text)
    self
  end
end

.supported_format?(text) ⇒ Boolean

Whether the given raw NOTAM text message is in a supported format.

Returns:

  • (Boolean)


100
101
102
# File 'lib/notam/message.rb', line 100

def supported_format?(text)
  !text.match? UNSUPPORTED_FORMATS
end

Instance Method Details

#active?(at:) ⇒ Boolean

Whether the NOTAM is active at the given time.

Parameters:

  • at (Time)

Returns:

  • (Boolean)


71
72
73
74
# File 'lib/notam/message.rb', line 71

def active?(at:)
  (data[:effective_at]..data[:expiration_at]).include?(at) &&
    (!(d_item = item(:D)) || d_item.active?(at: at))
end

#inspectObject Also known as: to_s



62
63
64
# File 'lib/notam/message.rb', line 62

def inspect
  %Q(#<#{self.class} #{data[:id]}>)
end

#item(type) ⇒ Object

Item of the given type

Parameters:

  • type (Symbol, nil)

    either :Header, :Q, (:A..:G) or :Footer



79
80
81
# File 'lib/notam/message.rb', line 79

def item(type)
  items.find { _1.type == type }
end