Class: AIPP::LF::AD31

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

Overview

Helipads

Constant Summary collapse

DEPENDS =
%w(AD-2)
HOSTILITIES =
{
  'zone hostile habitée' => 'Zone hostile habitée / hostile populated area',
  'zone hostile non habitée' => 'Zone hostile non habitée / hostile unpopulated area',
  'zone non hostile' => 'Zone non hostile / non-hostile area'
}.freeze
POSITIONINGS =
{
  'en terrasse' => 'En terrasse / on deck',
  'en surface' => 'En surface / on ground'
}.freeze
DIMENSIONS_RE =
/( diam.tre\s+\d+ | (?:\d[\s\d,.m]*x\s*){1,}[\s\d,.m]+ )/ix.freeze

Constants included from Helpers::Common

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

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



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
78
79
80
81
82
83
84
85
86
# File 'lib/aipp/regions/LF/AD-3.1.rb', line 25

def parse
  prepare(html: read).css('tbody').each do |tbody|
    tbody.css('tr').to_enum.each_slice(3).with_index(1) do |trs, index|
      name = trs[0].css('span[id*="ADHP.TXT_NAME"]').text.cleanup.remove(/[^\w' ]/)
      if select(:airport, name: name).any?
        verbose_info "Skipping #{name} in favor of AD-2"
        next
      end
      # Airport
      @airport = AIXM.airport(
        source: source(position: trs[0].line),
        organisation: organisation_lf,   # TODO: not yet implemented
        id: options[:region],
        name: name,
        xy: xy_from(trs[1].css('td:nth-of-type(1)').text.cleanup)
      ).tap do |airport|
        airport.z = elevation_from(trs[1].css('td:nth-of-type(2)').text)
      end
      # Usage restrictions
      if trs[0].css('span[id*="ADHP.STATUT"]').text.match?(/usage\s+restreint/i)
        @airport.add_usage_limitation(:reservation_required) do |reservation_required|
          reservation_required.remarks = "Usage restreint / restricted use"
        end
      end
      if trs[0].css('span[id*="ADHP.STATUT"]').text.match?(/r.serv.\s+aux\s+administrations/i)
        @airport.add_usage_limitation(:other) do |other|
          other.remarks = "Réservé aux administrations de l'État / reserved for State administrations"
        end
      end
      # FATOs and helipads
      text = trs[2].css('span[id*="ADHP.REVETEMENT"]').text.remove(/tlof\s*|\s*\(.*?\)/i).downcase
      surface = text.blank? ? {} : SURFACES.metch(text)
      lighting = lighting_from(trs[1].css('span[id*="ADHP.BALISAGE"]').text.cleanup)
      fatos_from(trs[1].css('span[id*="ADHP.DIM_FATO"]').text).each { |f| @airport.add_fato f }
      helipads_from(trs[1].css('span[id*="ADHP.DIM_TLOF"]').text).each do |helipad|
        helipad.surface.composition = surface[:composition]
        helipad.surface.preparation = surface[:preparation]
        helipad.surface.remarks = surface[:remarks]
        helipad.surface.auw_weight = auw_weight_from(trs[2].css('span[id*="ADHP.RESISTANCE"]').text)
        helipad.add_lighting(lighting) if lighting
        @airport.add_helipad helipad
      end
      # Operator and addresses
      operator = trs[0].css('span[id*="ADHP.EXPLOITANT"]')
      splitted = operator.text.split(/( (?<!\p{L})t[ée]l | fax | standard | [\d\s]{10,} | \.\s | \( )/ix, 2)
      @airport.operator = splitted[0].full_strip.truncate(60, omission: '').blank_to_nil
      raw_addresses = splitted[1..].join.cleanup.full_strip
      addresses_from(splitted[1..].join, source(position: operator.first.line)).each { |a| @airport.add_address(a) }
      # Remarks
      @airport.remarks = [].tap do |remarks|
        hostility = trs[2].css('span[id*="ADHP.ZONE_HABITEE"]').text.cleanup.downcase.blank_to_nil
        hostility = HOSTILITIES.fetch(hostility) if hostility
        positioning = trs[2].css('span[id*="ADHP.EN_TERRASSE"]').text.cleanup.downcase.blank_to_nil
        positioning = POSITIONINGS.fetch(positioning) if positioning
        remarks << ('**SITUATION**' if hostility || positioning) << hostility << positioning << ''
        remarks << trs[2].css('td:nth-of-type(5)').text.cleanup
        remarks << raw_addresses unless raw_addresses.blank?
      end.compact.join("\n").strip
      add(@airport) if @airport.fatos.any? || @airport.helipads.any?
    end
  end
end