Class: AIPP::LF::ENR55

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

Overview

Sporting and Recreational Activities

Constant Summary collapse

ACTIVITIES =

Map raw activities to activity and airspace type

{
  'activité particulière' => { activity: :other, airspace_type: :dangerous_activities_area },
  'aéromodélisme' => { activity: :aeromodelling, airspace_type: :dangerous_activities_area },
  'parachutage' => { activity: :parachuting, airspace_type: :dangerous_activities_area },
  'treuillage' => { activity: :glider_winch, airspace_type: :dangerous_activities_area },
  'voltige' =>  { activity: :acrobatics, airspace_type: :dangerous_activities_area }
}.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


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

def parse
  prepare(html: read).css('tbody').each do |tbody|
    tbody.css('tr').to_enum.each_slice(2).with_index(1) do |trs, index|
      begin
        id, activity_and_name, upper_limit, timetable = trs.first.css('td')
        activity, name = activity_and_name.css('span')
        lateral_limit, lower_limit, remarks = trs.last.css('td')
        lateral_limit.search('br').each { _1.replace("|||") }
        geometry, lateral_limit = lateral_limit.text.split('|||', 2)
        lateral_limit&.gsub!('|||', "\n")
        remarks = [remarks&.text&.cleanup&.blank_to_nil]
        s = timetable&.text&.cleanup and remarks.prepend('**SCHEDULE**', s, '')
        s = lateral_limit&.cleanup and remarks.prepend('**LATERAL LIMIT**', s, '')
        airspace = AIXM.airspace(
          source: source(position: trs.first.line),
          id: id.text.strip,
          type: ACTIVITIES.fetch(activity.text.downcase).fetch(:airspace_type),
          name: [id.text.strip, name.text.cleanup].join(' ')
        ).tap do |airspace|
          airspace.geometry = geometry_from(geometry)
          airspace.add_layer(
            layer_from([upper_limit.text, lower_limit.text].join('---').cleanup).tap do |layer|
              layer.activity = ACTIVITIES.fetch(activity.text.downcase).fetch(:activity)
              layer.remarks = remarks.compact.join("\n")
            end
          )
        end
      rescue => error
        warn("error parsing #{airspace.type} `#{airspace.name}' at ##{index}: #{error.message}", pry: error)
      end
      add airspace
    end
  end
end