Class: AIPP::LF::ENR51

Inherits:
AIP show all
Includes:
Helpers::Common
Defined in:
lib/aipp/regions/LF/ENR-5.1.rb

Overview

D/P/R Zones

Constant Summary collapse

SOURCE_TYPES =

Map source types to type and optional local type

{
  'D' => { type: 'D' },
  'P' => { type: 'P' },
  'R' => { type: 'R' },
  'ZIT' => { type: 'P', local_type: 'ZIT' }
}.freeze

Constants included from Helpers::Common

Helpers::Common::ANGLICISE_MAP, Helpers::Common::BORDERS, Helpers::Common::INTERSECTIONS, Helpers::Common::SURFACES

Constants inherited from AIP

AIP::DEPENDS

Instance Attribute Summary

Attributes inherited from AIP

#aip, #fixture

Instance Method Summary collapse

Methods included from Helpers::Common

#anglicise, #elevation_from, #geometry_from, #layer_from, #organisation_lf, #prepare, #source, #timetable_from!, #xy_from, #z_from

Methods inherited from AIP

#add, #borders, #cache, #close, #config, #initialize, #options, #read, #select

Methods included from Patcher

#attach_patches, #detach_patches

Constructor Details

This class inherits a constructor from AIPP::AIP

Instance Method Details

#parseObject



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
# File 'lib/aipp/regions/LF/ENR-5.1.rb', line 17

def parse
  prepare(html: read).css('tbody:has(tr[id^=mid])').each do |tbody|
    airspace = nil
    tbody.css('tr').to_enum.with_index(1).each do |tr, index|
      tds = tr.css('td')
      case
      when tr.attr(:id).match?(/TXT_NAME/)   # airspace
        airspace = airspace_from tr
      when tds.count == 1   # big comment on separate row
        airspace.layers.first.remarks.
          concat("\n", tds.text.cleanup).
          remove!(/\((\d)\)\s*\(\1\)\W*/)
      else   # layer
        begin
          tds = tr.css('td')
          airspace.geometry = geometry_from tds[0].text
          fail("geometry is not closed") unless airspace.geometry.closed?
          airspace.layers << layer_from(tds[1].text)
          airspace.layers.first.timetable = timetable_from! tds[2].text
          airspace.layers.first.remarks = remarks_from(tds[2], tds[3], tds[4])
          add airspace
        rescue => error
          warn("error parsing airspace `#{airspace.name}' at ##{index}: #{error.message}", pry: error)
        end
      end
    end
  end
end