Class: NOTAM::Header

Inherits:
Item
  • Object
show all
Defined in:
lib/notam/item/header.rb

Overview

The header item contains the NOTAM ID as well as information as to whether its a new NOTAM or merely replacing or cancelling another one.

Constant Summary collapse

RE =
%r(
  \A
  (?<id>#{ID_RE})\s+
  NOTAM(?<operation>[NRC])\s*
  (?<old_id>#{ID_RE.decapture})?
  \z
)x.freeze

Constants inherited from Item

Item::ICAO_RE, Item::ID_RE, Item::TIME_RE

Instance Attribute Summary

Attributes inherited from Item

#captures, #data, #text

Instance Method Summary collapse

Methods inherited from Item

#fail!, #initialize, type, #type

Constructor Details

This class inherits a constructor from NOTAM::Item

Instance Method Details

#cancelsString?

Returns message being cancelled by this message or nil if this message is a new or replacing one.

Returns:

  • (String, nil)

    message being cancelled by this message or nil if this message is a new or replacing one



53
54
55
# File 'lib/notam/item/header.rb', line 53

def cancels
  captures['old_id'] if captures['operation'] == 'C'
end

#idString

Returns ID of this message.

Returns:

  • (String)

    ID of this message



20
21
22
# File 'lib/notam/item/header.rb', line 20

def id
  captures['id']
end

#id_numberInteger

Returns serial number.

Returns:

  • (Integer)

    serial number



30
31
32
# File 'lib/notam/item/header.rb', line 30

def id_number
  captures['id_number'].to_i
end

#id_seriesString

Returns series letter.

Returns:

  • (String)

    series letter



25
26
27
# File 'lib/notam/item/header.rb', line 25

def id_series
  captures['id_series']
end

#id_yearInteger

Returns year identifier.

Returns:

  • (Integer)

    year identifier



35
36
37
# File 'lib/notam/item/header.rb', line 35

def id_year
  captures['id_year'].to_i + (Date.today.year / 1000 * 1000)
end

#inspectString

Returns:

  • (String)


72
73
74
# File 'lib/notam/item/header.rb', line 72

def inspect
  %Q(#<#{self.class} "#{truncated_text(start: 0)}">)
end

#mergeObject

See Also:



67
68
69
# File 'lib/notam/item/header.rb', line 67

def merge
  super(:id, :id_series, :id_number, :id_year, :new?, :replaces, :cancels)
end

#new?Boolean

Returns true if this is a new message, false if it replaces or cancels another message.

Returns:

  • (Boolean)

    true if this is a new message, false if it replaces or cancels another message



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

def new?
  captures['operation'] == 'N'
end

#parseObject

See Also:



58
59
60
61
62
63
64
# File 'lib/notam/item/header.rb', line 58

def parse
  super
  fail! "invalid operation" unless (new? && !captures['old_id']) || replaces || cancels
  self
rescue
  fail! 'invalid Header item'
end

#replacesString?

Returns message being replaced by this message or nil if this message is a new or cancelling one.

Returns:

  • (String, nil)

    message being replaced by this message or nil if this message is a new or cancelling one



47
48
49
# File 'lib/notam/item/header.rb', line 47

def replaces
  captures['old_id'] if captures['operation'] == 'R'
end