Class: NOTAM::D
Overview
The D item contains timesheets to further narrow when exactly the NOTAM is effective.
Constant Summary
Constants inherited from Item
Item::ICAO_RE, Item::ID_RE, Item::RE, Item::TIME_RE
Instance Attribute Summary collapse
-
#schedules ⇒ Array<NOTAM::Schedule>
readonly
Activity schedules.
Attributes inherited from Item
Instance Method Summary collapse
-
#active?(at:) ⇒ Boolean
Whether the D item is active at the given time.
-
#five_day_schedules ⇒ Array<NOTAM::Schedule>
Calculate the relevant, consolidated schedules for five days.
- #merge ⇒ Object
- #parse ⇒ Object
Methods inherited from Item
#fail!, #initialize, #inspect, type, #type
Constructor Details
This class inherits a constructor from NOTAM::Item
Instance Attribute Details
#schedules ⇒ Array<NOTAM::Schedule> (readonly)
Activity schedules
12 13 14 |
# File 'lib/notam/item/d.rb', line 12 def schedules @schedules end |
Instance Method Details
#active?(at:) ⇒ Boolean
Whether the D item is active at the given time.
31 32 33 |
# File 'lib/notam/item/d.rb', line 31 def active?(at:) schedules.any? { _1.active?(at: at, xy: data[:center_point]) } end |
#five_day_schedules ⇒ Array<NOTAM::Schedule>
Calculate the relevant, consolidated schedules for five days.
The beginning of the five day window is either today (if effective_at
is in the past) or effective_at
(otherwise).
41 42 43 44 45 46 47 |
# File 'lib/notam/item/d.rb', line 41 def five_day_schedules schedules.map do |schedule| schedule .slice(AIXM.date(five_day_base), AIXM.date(five_day_base + 4 * 86_400)) .resolve(on: AIXM.date(five_day_base), xy: data[:center_point]) end.map { _1 unless _1.empty? }.compact end |
#merge ⇒ Object
50 51 52 |
# File 'lib/notam/item/d.rb', line 50 def merge super(:schedules, :five_day_schedules) end |
#parse ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/notam/item/d.rb', line 15 def parse base_date = AIXM.date(data[:effective_at]) @schedules = text.sub(/\AD\)/, '').split(',').flat_map do |string| Schedule.parse(string, base_date: base_date).tap do |schedule| base_date = schedule.last.last_date || base_date # carry over month end end self rescue fail! 'invalid D item' end |