class AIPP::LF::AD31
Helipads
Constants
- DEPENDS
- DIMENSIONS_RE
- HOSTILITIES
- POSITIONINGS
Public Instance Methods
parse()
click to toggle source
# File lib/aipp/regions/LF/AD-3.1.rb 25 def parse 26 prepare(html: read).css('tbody').each do |tbody| 27 tbody.css('tr').to_enum.each_slice(3).with_index(1) do |trs, index| 28 name = trs[0].css('span[id*="ADHP.TXT_NAME"]').text.cleanup.remove(/[^\w' ]/) 29 if find_by(:airport, name: name).any? 30 verbose_info "Skipping #{name} in favor of AD-2" 31 next 32 end 33 # Airport 34 @airport = AIXM.airport( 35 source: source(position: trs[0].line), 36 organisation: organisation_lf, # TODO: not yet implemented 37 id: options[:region], 38 name: name, 39 xy: xy_from(trs[1].css('td:nth-of-type(1)').text.cleanup) 40 ).tap do |airport| 41 airport.z = elevation_from(trs[1].css('td:nth-of-type(2)').text) 42 end 43 # Usage restrictions 44 if trs[0].css('span[id*="ADHP.STATUT"]').text.match?(/usage\s+restreint/i) 45 @airport.add_usage_limitation(type: :reservation_required) do |reservation_required| 46 reservation_required.remarks = "Usage restreint / restricted use" 47 end 48 end 49 if trs[0].css('span[id*="ADHP.STATUT"]').text.match?(/r.serv.\s+aux\s+administrations/i) 50 @airport.add_usage_limitation(type: :other) do |other| 51 other.remarks = "Réservé aux administrations de l'État / reserved for State administrations" 52 end 53 end 54 # FATOs and helipads 55 text = trs[2].css('span[id*="ADHP.REVETEMENT"]').text.remove(/tlof\s*|\s*\(.*?\)/i).downcase.compact 56 surface = text.blank? ? {} : SURFACES.metch(text) 57 lighting = lighting_from(trs[1].css('span[id*="ADHP.BALISAGE"]').text.cleanup) 58 fatos_from(trs[1].css('span[id*="ADHP.DIM_FATO"]').text).each { @airport.add_fato(_1) } 59 helipads_from(trs[1].css('span[id*="ADHP.DIM_TLOF"]').text).each do |helipad| 60 helipad.surface.composition = surface[:composition] 61 helipad.surface.preparation = surface[:preparation] 62 helipad.surface.remarks = surface[:remarks] 63 helipad.surface.auw_weight = auw_weight_from(trs[2].css('span[id*="ADHP.RESISTANCE"]').text) 64 helipad.add_lighting(lighting) if lighting 65 @airport.add_helipad helipad 66 end 67 # Operator and addresses 68 operator = trs[0].css('span[id*="ADHP.EXPLOITANT"]') 69 splitted = operator.text.split(/( (?<!\p{L})t[ée]l | fax | standard | [\d\s]{10,} | \.\s | \( )/ix, 2) 70 @airport.operator = splitted[0].full_strip.truncate(60, omission: '…').blank_to_nil 71 raw_addresses = splitted[1..].join.cleanup.full_strip 72 addresses_from(splitted[1..].join, source(position: operator.first.line)).each { @airport.add_address(_1) } 73 # Remarks 74 @airport.remarks = [].tap do |remarks| 75 hostility = trs[2].css('span[id*="ADHP.ZONE_HABITEE"]').text.cleanup.downcase.blank_to_nil 76 hostility = HOSTILITIES.fetch(hostility) if hostility 77 positioning = trs[2].css('span[id*="ADHP.EN_TERRASSE"]').text.cleanup.downcase.blank_to_nil 78 positioning = POSITIONINGS.fetch(positioning) if positioning 79 remarks << ('**SITUATION**' if hostility || positioning) << hostility << positioning << '' 80 remarks << trs[2].css('td:nth-of-type(5)').text.cleanup 81 remarks << raw_addresses unless raw_addresses.blank? 82 end.compact.join("\n").strip 83 add(@airport) if @airport.fatos.any? || @airport.helipads.any? 84 end 85 end 86 end
Private Instance Methods
addresses_from(text, source)
click to toggle source
# File lib/aipp/regions/LF/AD-3.1.rb 139 def addresses_from(text, source) 140 [].tap do |addresses| 141 text.sub! /(?<!\p{L})t[ée]l\D*([\d\s.]{10,}(?:poste[\d\s.]{2,})?)[-\/]?/i do |m| 142 addresses << AIXM.address( 143 source: source, 144 type: :phone, 145 address: m.strip.sub(/poste/i, '-').remove(/[^\d-]|-$/) 146 ) 147 end 148 text.sub! /fax\D*([\d\s.]{10,}(?:poste[\d\s.]{2,})?)[-\/]?/i do |m| 149 addresses << AIXM.address( 150 source: source, 151 type: :fax, 152 address: m.strip.sub(/poste/i, '-').remove(/[^\d-]|-$/) 153 ) 154 end 155 text.sub! /e-mail\W*(\S+)[-\/]?/i do |m| 156 addresses << AIXM.address( 157 source: source, 158 type: :email, 159 address: m.strip 160 ) 161 end 162 text.sub! /(\d[\d\s]{9,}(?:poste[\d\s.]{2,})?)[-\/]?/i do |m| 163 addresses << AIXM.address( 164 source: source, 165 type: :phone, 166 address: m.strip.sub(/poste/i, '-').remove(/[^\d-]|-$/) 167 ) 168 end 169 end 170 end
auw_weight_from(text)
click to toggle source
# File lib/aipp/regions/LF/AD-3.1.rb 125 def auw_weight_from(text) 126 if wgt = text.match(/(\d+(?:[,.]\d+)?)\s*t/i)&.captures&.first 127 AIXM.w(wgt.to_ff, :t) 128 end 129 end
dimensions_from(text)
click to toggle source
# File lib/aipp/regions/LF/AD-3.1.rb 111 def dimensions_from(text) 112 dims = text.remove(/[^x\d.,]/i).split(/x/i).map { _1.to_ff.floor } 113 case dims.size 114 when 1 115 [dim = AIXM.d(dims[0], :m), dim] 116 when 2 117 [AIXM.d(dims[0], :m), AIXM.d(dims[1], :m)] 118 when 4 119 [dim = AIXM.d(dims.min, :m), dim] 120 else 121 warn("bad dimensions for #{@airport.name}", pry: binding) 122 end 123 end
fatos_from(text)
click to toggle source
# File lib/aipp/regions/LF/AD-3.1.rb 90 def fatos_from(text) 91 [ 92 if text.cleanup.match DIMENSIONS_RE 93 AIXM.fato(name: 'FATO').tap do |fato| 94 fato.length, fato.width = dimensions_from($1) 95 end 96 end 97 ].compact 98 end
helipads_from(text)
click to toggle source
# File lib/aipp/regions/LF/AD-3.1.rb 100 def helipads_from(text) 101 [ 102 if text.cleanup.match DIMENSIONS_RE 103 AIXM.helipad(name: 'TLOF', xy: @airport.xy).tap do |helipad| 104 helipad.z = @airport.z 105 helipad.length, helipad.width = dimensions_from($1) 106 end 107 end 108 ].compact 109 end
lighting_from(text)
click to toggle source
# File lib/aipp/regions/LF/AD-3.1.rb 131 def lighting_from(text) 132 return if text.blank? || text.match?(/nil|balisage\s*:\s*non/i) 133 description = text.remove(/balisage\s*:|oui\.?\s*:?/i).compact.full_strip 134 AIXM.lighting(position: :edge).tap do |lighting| 135 lighting.description = description unless description.blank? 136 end 137 end