Class: AIPP::LF::ENR51

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

Overview

D/P/R Zones

Constant Summary collapse

SECTIONS =

Map sections to whether to parse them

{
  '5.1-1':   true,
  '5.1-2':   false,
  '5.1-3':   true,
  '5.1-4':   true,
  '5.1-5-1': false,
  '5.1-5-2': true
}
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
POINT_RADIUS =

Radius to use for zones consisting of one point only

AIXM.d(1, :km).freeze

Constants included from Helpers::Base

Helpers::Base::ANGLICISE_MAP, Helpers::Base::BORDERS, Helpers::Base::INTERSECTIONS, Helpers::Base::SURFACES

Constants inherited from AIP

AIP::DEPENDS

Instance Attribute Summary

Attributes inherited from AIP

#aip, #fixture

Instance Method Summary collapse

Methods included from Helpers::Base

#anglicise, #d_from, #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, #find, #find_by, #initialize, #options, #read

Methods included from Patcher

#attach_patches, #detach_patches, included

Constructor Details

This class inherits a constructor from AIPP::AIP

Instance Method Details

#parseObject


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

def parse
  skip = false
  prepare(html: read).css('h4, thead ~ tbody').each do |tag|
    case tag.name
    when 'h4'
      section = tag.text.match(/^ENR ([\d.-]+)/).captures.first
      skip = !SECTIONS.fetch(section.to_sym)
      verbose_info "#{skip ? :Skipping : :Parsing} section #{section}"
    when 'tbody'
      next if skip
      airspace = nil
      tag.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
            if airspace.geometry.point?   # convert point to circle
              airspace.geometry = AIXM.geometry(
                AIXM.circle(
                  center_xy: airspace.geometry.segments.first.xy,
                  radius: POINT_RADIUS
                )
              )
            end
            fail("geometry is not closed") unless airspace.geometry.closed?
            airspace.add_layer 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])
            if aixm.features.find_by(:airspace, type: airspace.type, id: airspace.id).none?
              add airspace
            end
          rescue => error
            warn("error parsing airspace `#{airspace.name}' at ##{index}: #{error.message}", pry: error)
          end
        end
      end
    end
  end
end