Class: AIPP::LS::NOTAM::ENR

Inherits:
NOTAM::Parser show all
Includes:
Helpers::Base
Defined in:
lib/aipp/regions/LS/notam/ENR.rb

Instance Attribute Summary

Attributes inherited from Parser

#aixm

Instance Method Summary collapse

Methods included from Helpers::Base

#organisation_ls, #origin_for, #timetable_from

Methods inherited from Parser

#add, dependencies, depends_on, #find, #find_by, #given, #initialize, #inspect, #link_to, #origin_for, #read, #section

Methods included from Patcher

#attach_patches, #detach_patches, included

Methods included from Debugger

#info, #original_warn, #verbose_info, #warn, #with_debugger

Constructor Details

This class inherits a constructor from AIPP::Parser

Instance Method Details

#parseObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/aipp/regions/LS/notam/ENR.rb', line 8

def parse
  AIPP.cache.aip ||= read('AIP').css('Ase')
  AIPP.cache.dabs ||= read('DABS')
  json = read
  fail "malformed JSON received from API" unless json.has_key?(:queryNOTAMs)
  added_notam_ids = []
  json[:queryNOTAMs].each do |row|
    next unless row[:notamRaw].match? /^Q\) LS/   # only parse national NOTAM

# HACK: try to add missing commas to D-item of A- and B-series NOTAM
# if row[:notamRaw].match? /\A[AB]/
#   if row[:notamRaw].gsub!(/(#{NOTAM::Schedule::HOUR_RE.decapture}-#{NOTAM::Schedule::HOUR_RE.decapture})/, '\1,')
#     row[:notamRaw].gsub!(/,+/, ',')
#     row[:notamRaw].sub!(/,\n/, "\n")
#     warn("HACK: added missing commas to D item")
#   end
# end

# HACK: remove braindead years from D-item of W-series NOTAM
if row[:notamRaw].match? /\AW/
  year = Time.now.year
  if row[:notamRaw].gsub!(/\s*(?:#{year}|#{year+1})\s*(#{NOTAM::Schedule::MONTH_RE})/, ' \1')
warn("HACK: removed braindead years from D item")
  end
end

    (notam = notam_for(row[:notamRaw])) or next
    if respect? notam
      next if notam.data[:five_day_schedules] == []
      added_notam_ids << notam.data[:id]
      add(
        case notam.data[:content]
        when /\A[DR].AREA.+ACT/, /TMA.+ACT/
          if fragment = fragment_for(notam)
            AIXM.generic(fragment: fragment_for(notam)).tap do |airspace|
              element = airspace.fragment.children.first
              element.prepend_child(['<!--', notam.text ,'-->'].join("\n"))
              content = ["NOTAM #{notam.data[:id]}", element.at_css('txtName').content].join(": ").strip
              element.at_css('txtName').content = content
              content = [element.at_css('txtRmk')&.text, notam.data[:translated_content]].join("\n").strip
              element.find_or_add_child('txtRmk').content = content
              if schedule = notam.data[:five_day_schedules]
                timetable = timetable_from(schedule)
                element
                  .find_or_add_child('Att', before_css: %w(codeSelAvbl txtRmk))
                  .replace(timetable.to_xml(as: :Att).chomp)
              end
            end
          else
            warn "no feature found for `#{notam.data[:content]}' - fallback to point and radius"
            airspace_from(notam).tap do |airspace|
              airspace.geometry = geometry_from_q_item(notam)
            end
          end
        when /\ATEMPO [DR].AREA.+(?:ACT|EST|ESTABLISHED) WI AREA/
          airspace_from(notam).tap do |airspace|
            airspace.geometry = geometry_from_content(notam)
          end
        else
          airspace_from(notam).tap do |airspace|
            airspace.geometry = geometry_from_q_item(notam)
          end
        end
      )
    else
      verbose_info("Skipping NOTAM #{notam.data[:id]}")
    end
  end
  dabs_cross_check(added_notam_ids)
end