module AIPP::LF::Helpers::RadioAD
Constants
- ADDRESS_TYPES
Service types to be encoded as addresses
- IGNORED_TYPES
Service types to be ignored
- SERVICE_TYPES
Unknown service types to be encoded as units
Public Instance Methods
addresses_from(trs)
click to toggle source
# File lib/aipp/regions/LF/helpers/radio_AD.rb 18 def addresses_from(trs) 19 return [] if trs.text.blank? 20 trs.map do |tr| 21 tds = tr.css('td') 22 type = tds[0].text.strip 23 next if IGNORED_TYPES.include? type 24 f, callsign, _, remarks = parts_from(tds).values 25 callsign = callsign.split(/\n\s*/).join('/') 26 if ADDRESS_TYPES.include?(type) 27 AIXM.address( 28 source: source(position: tr.line), 29 type: :radio_frequency, 30 address: f.freq.to_s 31 ).tap do |address| 32 address.remarks = ["#{type} - indicatif/callsign #{callsign}", remarks.blank_to_nil].compact.join("\n") 33 end 34 end 35 end.compact 36 end
units_from(trs, airport:)
click to toggle source
# File lib/aipp/regions/LF/helpers/radio_AD.rb 38 def units_from(trs, airport:) 39 return [] if trs.text.blank? 40 trs.each_with_object({}) do |tr, services| 41 tds = tr.css('td') 42 type = tds[0].text.strip 43 next if IGNORED_TYPES.include?(type) || ADDRESS_TYPES.include?(type) 44 f, callsigns, timetable, remarks = parts_from(tds).values 45 callsigns = if callsigns.match?(/\(\w{2}\)/) 46 callsigns.cleanup.split("\n").each_with_object({}) do |callsign, hash| 47 callsign =~ /^(.*)\s+\((\w{2})\)/ 48 hash[$2.downcase.to_sym] = $1 49 end 50 else 51 { fr: callsigns } 52 end 53 if SERVICE_TYPES.include? type 54 type = SERVICE_TYPES.dig(type, :type) 55 remarks = [SERVICE_TYPES.dig(type, :remarks), remarks.blank_to_nil].compact.join("\n") 56 end 57 unless services.include? type 58 @source = source(position: tr.line) # TODO 59 services[type] = AIXM.service( 60 # TODO: add source as soon as it is supported by components 61 # source: source(position: tr.line), 62 type: type 63 ) 64 end 65 code = $1 if timetable.sub!(/(#{AIXM::H_RE})\b/, '') 66 services[type].add_frequency( 67 AIXM.frequency( 68 transmission_f: f, 69 callsigns: callsigns 70 ).tap do |frequency| 71 frequency.type = :standard 72 frequency.type = :alternative if remarks.sub!(%r{fréquence supplétive/auxiliary frequency\S*}i, '') 73 frequency.timetable = AIXM.timetable(code: code) if code 74 frequency.remarks = [remarks, timetable.blank_to_nil].compact.join("\n").cleanup.blank_to_nil 75 end 76 ) 77 end.values.each_with_object(AIXM::Association::Array.new) do |service, units| 78 type = service.guessed_unit_type 79 unit = units.find_by(:unit, name: airport.id, type: type).first 80 unless unit 81 unit = AIXM.unit( 82 source: @source, # TODO 83 organisation: organisation_lf, # TODO: not yet implemented 84 type: type, 85 name: airport.id, 86 class: :icao # TODO: verify whether all units are ICAO 87 ).tap do |unit| 88 unit.airport = airport 89 end 90 units.send(:push, unit) 91 end 92 unit.add_service(service) 93 end 94 end
Private Instance Methods
parts_from(tds)
click to toggle source
# File lib/aipp/regions/LF/helpers/radio_AD.rb 98 def parts_from(tds) 99 { 100 f: AIXM.f(tds[2].css('span').first.text.to_f, tds[2].css('span').last.text), 101 callsign: tds[1].text.strip, 102 timetable: tds[3].text.strip, 103 remarks: tds[4].text.strip.sub(/Canal (8.33|25)/i, '') # TEMP: ignore canal spacing warnings 104 } 105 end